Skip to content

Instantly share code, notes, and snippets.

@TboneDubu
Created February 15, 2019 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TboneDubu/815a63824d85c26251249f4ff3c4f385 to your computer and use it in GitHub Desktop.
Save TboneDubu/815a63824d85c26251249f4ff3c4f385 to your computer and use it in GitHub Desktop.
Trouble Exporting to CSV - Some fields missing in exported CSV file
<?php
/**
* PHP Grid Component
*
* @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
* @version 2.0.0
* @license: see license.txt included in package
*/
include("C:\\xampp\\htdocs\\php_grid\\ADIMaster\\auth.php");
// include db config
include_once("../configmaster.php");
// include and create object
//include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
// Database config file to be passed in phpgrid constructor
$db_conf = array(
"type" => PHPGRID_DBTYPE,
"server" => PHPGRID_DBHOST,
"user" => PHPGRID_DBUSER,
"password" => PHPGRID_DBPASS,
"database" => PHPGRID_DBNAME
);
$g = new jqgrid($db_conf);
//$opt["caption"] = "Theme Selector";
//$g->set_options($opt);
$grid["sortname"] = 'id'; // by default sort grid by this field
$grid["sortorder"] = "desc"; // ASC or DESC
$grid["caption"] = "ARSS"; // caption of grid
$grid["width"] = 100; // some fixed width
$grid["autowidth"] = false;
$grid["shrinkToFit"] = false;// dont shrink to fit on screen
$grid["autoheight"] = true; // expand grid to screen height
//$grid["resizable"] = true;
//$grid["rownumWidth"] = 30;
//$grid["responsive"] = true;
$grid["multiselect"] = true; // allow you to multi-select through checkboxes
$grid["altRows"] = true;
$grid["altclass"] = "myAltRowClass";
// show append or replace option on step2
$grid["import"]["allowreplace"] = true;
// remove unwanted field in import mapping
$grid["import"]["hidefields"] = array("client_id");
$grid["sortable"] = false; // it is required for freezed column feature
$g->set_options($grid);
$g->set_actions(array(
"add"=>true, // allow/disallow add
"edit"=>true, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"rowactions"=>true, // show/hide row wise edit/del/save option
"export_excel"=>true, // export excel button
//"export_pdf"=>true, // export pdf button
"export_csv"=>true, // export csv button
"autofilter" => true, // show/hide autofilter for search
"showhidecolumns" => true, // show/hide columns
"search" => "advance", // show single/multi field search condition (e.g. simple or advance)
"import" => true
)
);
/*$g->select_command = "SELECT id, invdate, invheader.client_id, name, amount, note FROM invheader
INNER JOIN clients on clients.client_id = invheader.client_id
";
*/
$g->select_command = "SELECT i.pid, i.servicedescription, i.iotype, i.area, i.subarea,
i.location, i.buildingequipment,
a.id, a.tag, a.llalarm, a.llalmpriority, a.almoriginll, a.llsddelay,
a.loalarm, a.loalmpriority, a.almoriginlo, a.losddelay,
a.hialarm, a.hialmpriority, a.almoriginhi, a.hisddelay,
a.hhalarm, a.hhalmpriority, a.almoriginhh, a.hhsddelay,
a.maxcalibrange, a.mincalibrange, a.calibrangeunits, a.normalcontrolsp,
a.lowctrl, a.highctrl, a.comments
FROM tblarss a
INNER JOIN tblindex i ON i.tag = a.tag
";
// this db table will be used for add,edit,delete
$g->table = "tblarss";
//$cols = array();
$col = array();
$col["title"] = "ID";
$col["name"] = "id";
$col["width"] = "50";
$col["editable"] = false;
$col["search"] = true;
$col["export"] = false;
$col["hidden"]=true;
$col["frozen"] = true;
//$col["edittype"] = "lookup";
//$col["editoptions"] = array("size"=>20);//("table"=>"tblindex", "id"=>"id", "label"=>"Tag");
//$col["editrules"] = array("required"=>true); // and is required
//$col["show"] = array("edit"=>false); // only show freezed column in edit dialog
$cols[] = $col;
$col = array();
$col["title"] = "Tag";
$col["name"] = "tag";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["frozen"] = true;
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblindex", "id"=>"tag", "label"=>"Tag");
//$col["editrules"] = array("required"=>true); // and is required
//$col["show"] = array("edit"=>false); // only show freezed column in edit dialog
$cols[] = $col;
$col = array();
$col["title"] = "Service Description";
$col["name"] = "servicedescription";
$col["width"] = "200";
$col["editable"] = false;
$col["search"] = true;
$col["export"] = false;
//$col["frozen"] = true;
//$col["edittype"] = "lookup";
//$col["editoptions"] = array("size"=>20);//("table"=>"tblindex", "id"=>"id", "label"=>"Tag");
//$col["editrules"] = array("required"=>true); // and is required
////$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "PID";
$col["name"] = "pid";
$col["width"] = "100";
$col["editable"] = false;
$col["search"] = true;
$col["export"] = false;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["frozen"] = true;
$col["editoptions"] = array("table"=>"tblpid", "id"=>"pid", "label"=>"PID");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "Area";
$col["name"] = "area";
$col["width"] = "100";
$col["editable"] = false;
$col["search"] = true;
$col["export"] = false;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblarea", "id"=>"area", "label"=>"Area");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "SubArea";
$col["name"] = "subarea";
$col["width"] = "100";
$col["editable"] = false;
$col["search"] = true;
$col["export"] = false;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblsubarea", "id"=>"subarea", "label"=>"SubArea");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "Location";
$col["name"] = "location";
$col["width"] = "100";
$col["editable"] = false;
$col["search"] = true;
$col["export"] = false;
$col["align"] = "center";
$col["sortname"] = "id";
$col["sortorder"] = "asc"; //asc or desc
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tbllocation", "id"=>"location", "label"=>"Location");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "BuildingEquipment";
$col["name"] = "buildingequipment";
$col["width"] = "150";
$col["editable"] = false;
$col["search"] = true;
$col["export"] = false;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblbuildingequipment", "id"=>"buildingequipment", "label"=>"BuildingEquipment");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "IOType";
$col["name"] = "iotype";
$col["width"] = "50";
$col["editable"] = false;
$col["search"] = true;
$col["export"] = false;
$col["align"] = "center";
$grid["shrinkToFit"] = false; // dont shrink to fit on screen
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tbliotype", "id"=>"iotype", "label"=>"iotype");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "LLAlarm";
$col["name"] = "llalarm";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
//$col["edittype"] = "lookup";
//$col["editoptions"] = array("table"=>"tblline", "id"=>"line", "label"=>"Line");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "LLAlmPriority";
$col["name"] = "llalmpriority";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblpriority", "id"=>"priority", "label"=>"Priority");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "AlmOriginLL";
$col["name"] = "almoriginll";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblcontrolsystem", "id"=>"controlsystem", "label"=>"Controlsystem");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "LLSDDelay";
$col["name"] = "llsddelay";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tbltimedelay", "id"=>"timedelay", "label"=>"Timedelay");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "LoAlarm";
$col["name"] = "loalarm";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
//$col["edittype"] = "lookup";
//$col["editoptions"] = array("table"=>"tblline", "id"=>"line", "label"=>"Line");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "LoAlmPriority";
$col["name"] = "loalmpriority";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblpriority", "id"=>"priority", "label"=>"Priority");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "AlmOriginLo";
$col["name"] = "almoriginll";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblcontrolsystem", "id"=>"controlsystem", "label"=>"Controlsystem");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "LoSDDelay";
$col["name"] = "llsddelay";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tbltimedelay", "id"=>"timedelay", "label"=>"Timedelay");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "HiAlarm";
$col["name"] = "hialarm";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
//$col["edittype"] = "lookup";
//$col["editoptions"] = array("table"=>"tblline", "id"=>"line", "label"=>"Line");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "HiAlmPriority";
$col["name"] = "hialmpriority";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblpriority", "id"=>"priority", "label"=>"Priority");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "AlmOriginHi";
$col["name"] = "almoriginhi";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblcontrolsystem", "id"=>"controlsystem", "label"=>"Controlsystem");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "HiSDDelay";
$col["name"] = "hisddelay";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tbltimedelay", "id"=>"timedelay", "label"=>"Timedelay");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "HHAlarm";
$col["name"] = "hhalarm";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
//$col["edittype"] = "lookup";
//$col["editoptions"] = array("table"=>"tblline", "id"=>"line", "label"=>"Line");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "HHAlmPriority";
$col["name"] = "hhalmpriority";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblpriority", "id"=>"priority", "label"=>"Priority");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "AlmOriginHH";
$col["name"] = "almoriginhh";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblcontrolsystem", "id"=>"controlsystem", "label"=>"Controlsystem");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "HHSDDelay";
$col["name"] = "hhsddelay";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tbltimedelay", "id"=>"timedelay", "label"=>"Timedelay");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "MinCalibRange";
$col["name"] = "mincalibrange";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
//$col["edittype"] = "lookup";
//$col["editoptions"] = array("table"=>"tblline", "id"=>"line", "label"=>"Line");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "MaxCalibRange";
$col["name"] = "maxcalibrange";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
//$col["edittype"] = "lookup";
//$col["editoptions"] = array("table"=>"tblline", "id"=>"line", "label"=>"Line");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "CalibRangeUnits";
$col["name"] = "calibrangeunits";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
$col["edittype"] = "lookup";
$col["editoptions"] = array("table"=>"tblengunits", "id"=>"units", "label"=>"Units");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "NormalControlSP";
$col["name"] = "normalcontrolsp";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
//$col["edittype"] = "lookup";
//$col["editoptions"] = array("table"=>"tblline", "id"=>"line", "label"=>"Line");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "LowCtrl";
$col["name"] = "lowctrl";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
//$col["edittype"] = "lookup";
//$col["editoptions"] = array("table"=>"tblline", "id"=>"line", "label"=>"Line");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "HighCtrl";
$col["name"] = "highctrl";
$col["width"] = "100";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
//$col["edittype"] = "lookup";
//$col["editoptions"] = array("table"=>"tblline", "id"=>"line", "label"=>"Line");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "Comments";
$col["name"] = "comments";
$col["width"] = "200";
$col["editable"] = true;
$col["search"] = true;
$col["export"] = true;
$col["align"] = "center";
//$col["edittype"] = "lookup";
//$col["editoptions"] = array("table"=>"tblline", "id"=>"line", "label"=>"Line");
//$col["show"] = array("edit"=>false);
$cols[] = $col;
// pass the cooked columns to grid
$g->set_columns($cols);
// generate grid output, with unique grid name as 'list1'
$out = $g->render("list1");
$themes = array("metro-light","metro-dark","metro-black","base","black-tie","blitzer","cupertino","dark-hive","dot-luv","eggplant","excite-bike","flick","hot-sneaks","humanity","le-frog","mint-choc","overcast","pepper-grinder","redmond","smoothness","south-street","start","sunny","swanky-purse","trontastic","ui-darkness","ui-lightness","vader");
//$i = rand(0,26);
// if set from page
if (is_numeric($_GET["themeid"]))
$i = $_GET["themeid"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="../lib/js/themes/<?php echo $themes[$i]?>/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="../lib/js/jqgrid/css/ui.jqgrid.css"></link>
<script src="../lib/js/jquery.min.js" type="text/javascript"></script>
<script src="../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
<style>
.btn-group button {
background-color: #4CAF50; /* Green background */
border: 1px solid green; /* Green border */
color: white; /* White text */
padding: 5px 10px; /* Some padding */
cursor: pointer; /* Pointer/hand icon */
float: right; /* Float the buttons side by side */
margin-top: 0px;
}
.btn-group button:not(:last-child) {
border-right: none; /* Prevent double borders */
}
/* Clear floats (clearfix hack) */
.btn-group:after {
content: "";
clear: both;
display: table;
}
/* Add a background color on hover */
.btn-group button:hover {
background-color: #3e8e41;
}
h1 {text-align:center;display:inline; }
p {display:inline;text-align:right;}
</style>
<div id="header">
<img style="display: inline;" src="../adimaster/img/Stantec_logo.png" alt="logo" />
<h1>Automation Database Interface (ADI)</h1>
<!--<button type="button" style="position: absolute; right: 0 " onclick='location.href = "ADIdbtablegrid.php"; '>Edit Tables</button>
<button type="button" style="float: right;" onclick='location.href= "http://localhost/php_grid/adimaster/adiindex.php?logout=1";'>Logout</button-->
<div class="pull-right">
<div class="btn-group">
<button type="button" style="display: inline;" onclick='location.href= "http://localhost/php_grid/adimaster/adiindex.php?logout=1";'>Logout</button>
<button type="button" style="display: inline;" onclick='location.href = "ADIdbtablegrid.php"; '>Edit Tables</button>
<button type="button" style="display: inline;" onclick='location.href = "ADIIndex.php"; '>Index</button>
<button type="button" style="display: inline;" onclick='location.href= "http://localhost:8080/jasperserver/login.html";'>Reports</button>
</div>
</div>
<div style="position: absolute; right: 0 ">
</div>
</header>
</head>
<body>
<style>
/* fix for freeze column div position */
.ui-jqgrid .editable {margin: 0px !important;}
</style>
<script>
jQuery(document).ready(function(){
setTimeout(function(){
jQuery('#list1').jqGrid('navButtonAdd', '#list1_toppager',
{
'caption' : 'Freeze Mode',
'buttonicon' : 'ui-icon-extlink',
'onClickButton': function()
{
var t;
if (jQuery('div.frozen-bdiv').length == 0)
{
fx_freeze_grid('list1');
}
else
{
jQuery('#list1').jqGrid('destroyFrozenColumns');
}
},
'position': 'last'
});
jQuery('#list1').jqGrid('destroyFrozenColumns').trigger('reloadGrid', [{current:true}]);
jQuery(".ui-icon-plus").click(function(){ jQuery('#list1').jqGrid('destroyFrozenColumns'); });
},200);
});
</script>
<div style="margin:5px">
<form method="get">
<p> Choose Template:</p><select name="themeid" style="position: absolute; right: 0 " onchange="form.submit()">
<?php foreach($themes as $k=>$t) { ?>
<option value=<?php echo $k?> <?php echo ($i==$k)?"selected":""?>><?php echo ucwords($t)?></option>
<?php } ?>
</select>
</form>
</div>
<?php echo $out?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment