I have somehow managed to remove the sorting option from the grid columns.
I tried setting $col["sortable"] = true; on each of the columns but it still does not show.
Is there something else I need to enable?
Here is the code, first connect to DB and setup columns….
$conn = mysql_connect($dbhost,$dbuser,$dbpassword);
mysql_select_db($database);
mysql_query("SET NAMES 'utf8'");
include("lib/inc/jqgrid_dist.php");
$col = array();
$col["title"] = "pkey";
$col["name"] = "pkey";
$col["editable"] = false;
$col["width"] = "4";
$col["hidden"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "User";
$col["name"] = "username";
$col["width"] = "15";
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Emp";
$col["name"] = "emp_num";
$col["width"] = "15";
$col["editable"] = false;
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "First";
$col["name"] = "first_name";
$col["width"] = "15";
$col["editable"] = false;
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Last";
$col["name"] = "last_name";
$col["width"] = "15";
$col["editable"] = false;
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Driver";
$col["name"] = "driver_type";
$col["width"] = "15";
$col["editable"] = false;
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Truck";
$col["name"] = "truck_number";
$col["width"] = "10";
$col["editable"] = true;
$col["sortable"] = true;
$col["editoptions"] = array("size"=>5);
$cols[] = $col;
$col = array();
$col["title"] = "Real Start";
$col["name"] = "real_start";
$col["width"] = "35";
$col["editable"] = fasle;
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Pay Start";
$col["name"] = "pay_start";
$col["width"] = "35";
$col["editable"] = true;
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Real End";
$col["name"] = "real_end";
$col["width"] = "35";
$col["editable"] = fasle;
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Pay End";
$col["name"] = "pay_end";
$col["width"] = "35";
$col["editable"] = true;
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Hours";
$col["name"] = "hours";
$col["width"] = "10";
$col["editable"] = true;
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Stand By";
$col["name"] = "standby";
$col["width"] = "15";
$col["editable"] = true;
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Lunch";
$col["name"] = "lunch";
$col["width"] = "15";
$col["editable"] = true;
$col["edittype"] = "select";
$col["editoptions"] = array("value"=>'NO:NO;YES:YES');
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Dinner";
$col["name"] = "dinner";
$col["width"] = "15";
$col["editable"] = true;
$col["edittype"] = "select";
$col["editoptions"] = array("value"=>'NO:NO;YES:YES');
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Note";
$col["name"] = "emp_note";
$col["width"] = "50";
$col["search"] = true; // this column is not searchable
$col["editable"] = true;
$col["editoptions"] = array("rows"=>2, "cols"=>50); // with these attributes
$cols[] = $col;
//pay_type
$col = array();
$col["title"] = "Pay Type";
$col["name"] = "pay_type";
$col["editable"] = false;
$col["width"] = "1";
$col["hidden"] = true;
$cols[] = $col;
//truck_act_jonas
$col = array();
$col["title"] = "jonas";
$col["name"] = "truck_act_jonas";
$col["editable"] = false;
$col["width"] = "1";
$col["hidden"] = true;
$cols[] = $col;
// company_code
$col = array();
$col["title"] = "Comp Code";
$col["name"] = "company_code";
$col["editable"] = false;
$col["width"] = "1";
$col["hidden"] = true;
$cols[] = $col;
// approved
$col = array();
$col["title"] = "Approved";
$col["name"] = "approved";
$col["width"] = "18";
$col["editable"] = true;
$col["edittype"] = "select";
$col["editoptions"] = array("value"=>'NO:NO;YES:YES');
$col["sortable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Action";
$col["name"] = "act";
$col["width"] = "25";
$cols[] = $col;
//
Then setup the grid….
$g = new jqgrid();
$grid["caption"] = "Employee Time";
$grid["multiselect"] = true;
$grid["height"] = "550";
$grid["width"] = "1875";
$grid["scroll"] = false;
$grid["rowList"] = array();
$grid["rowNum"] = 20;
$grid["auto_width"] = false;
$grid["shrink_to_fit"] = true;
$grid["loadtext"] = true;
//$grid["altrows"] = true;
//$grid["sortname"] = 'truck_number';
//$grid["sortorder"] = "asc";
$g->set_options($grid);
// set db table
$g->table = "qcl_employee_time";
// pass the cooked columns to grid
$g->set_columns($cols);
$g->set_actions(array(
"add"=>fasle, // allow/disallow add
"edit"=>true, // allow/disallow edit
"delete"=>fasle, // allow/disallow delete
"rowactions"=>true, // show/hide row wise edit/del/save option
"export"=>false, // show/hide export to excel option
"autofilter" => true, // show/hide autofilter for search
"search" => "advance" // show single/multi field search condition (e.g. simple or advance)
)
);
// render grid
$out = $g->render("list1");
Your code seems fine. Sorting should be working as it is enabled by default. Is your solution somewhere online for review.
Next option would be share the sample db dump & code file, to regenerate the case.
Email me details at [email protected]
Thanks.
Just one more thing, if you make first column as editable false, your update/delete operations might not work as expected, because uneditable filed are not posted back and will fail in preparing DML sql.
I must have been playing around with the of the demo examples. I had….
<script>
var opts = {
'loadComplete': function () {
var $this = $(this), ids = $this.jqGrid('getDataIDs'), i, l = ids.length;
for (i = 0; i < l; i++) {
// list1 is the name of grid, passed in ->render() function
id = ids[i];
jQuery('#list1').editRow(id, true, function(){}, function(){
if (jQuery('#edit_row_list1_').val() != undefined)
{
jQuery('#edit_row_list1_'+id).show();
jQuery('#save_row_list1_'+id).hide();
}
return true;
},null,null,function(){
},null,
function(){
if (jQuery('#edit_row_list1_').val() != undefined)
{
jQuery('#edit_row_list1_'+id).show();
jQuery('#save_row_list1_'+id).hide();
}
return true;
}
);
jQuery('#edit_row_list1_'+id).hide();
jQuery('#save_row_list1_'+id).show();
}
}
};
</script>
before…..
<div style="margin:10px">
<?php echo $out?>
</div>
Once removed everything works great 🙂
Thanks for the help.