Because the server software I’m using (coldfusion) uses a non-standard JSON format, I’m having to remap the columns.
Unfortunately, once I do this, when using the toolbar search boxes, the grid queries the server rather than doing so locally — I set the loadonce:true parameter so that it would not query the server after the initial load.
Can anyone help me with this?
var gridCols = {set:false};
$(document).ready(function(){
var grid = $(‘#gridTest’); // JQuery object reference of table used for our grid display
/*
* FUNCTION populateGrid
* Used as the ‘datatype’ attribute of the jqGrid config object, this method
* is used to handle the ajax calls and data manipulation needed to populate
* data within our jqGrid instance.
* @postdata (object) – this is the object passed as the ‘postData’ attribute
* of our jqGrid instance.
*/
var populateGrid = function (postdata) {
$.ajax({
url: ‘./cfc/Schools.cfc’,
data:postdata,
method:’GET’,
dataType:”json”,
success: function(d,r,o){
if(d.SUCCESS){
// If loading for the first time, let’s find out to which
// array positions our columns map.
if(!gridCols.set){
for(var i in d.DATA.COLUMNS){
gridCols[d.DATA.COLUMNS] = parseInt(i);
}
gridCols.set = true;
}
grid.jqGrid(‘setGridParam’,{remapColumns:[
gridCols,
gridCols,
gridCols,
gridCols,
gridCols,
gridCols,
gridCols
]});
grid[0].addJSONData(d);
} else {
alert(d.MESSAGE);
}
}
});
};
grid.jqGrid({
loadonce: true,
gridview: true,
autowidth: true,
caption: ‘Schools’,
loadui: ‘block’,
altRows: true,
deepempty: true,
viewrecords: true,
sortname: ‘SCH_NAME’,
sortorder: ‘asc’,
colNames:,
colModel: [
{name:’SCH_ID’,index:’SCH_ID’,key:true,hidden:true},
{name:’SCH_NAME’,index:’SCH_NAME’,sorttype:’text’,resizable:true},
{name:’SCH_LOCATION_NAME’,index:’SCH_LOCATION_NAME’,sorttype:’text’,resizable:true},
{name:’SCH_IMAGEFILENAME’,index:’SCH_IMAGEFILENAME’,sorttype:’text’,resizable:true},
{name:’SCH_ACTIVE’,index:’SCH_ACTIVE’,width:60,align:’center’,stype:’select’,sorttype:’numeric’,editable:true,edittype:’checkbox’,search:true,formatter:’checkbox’,resizable:false,
editoptions: {
value: “1:Yes;0:No”
},
searchoptions: {
sopt:,
value: “:All;1:Yes;0:No”,
defaultValue: “1”
}},
{name:’CONFERENCENAME’,index:’CONFERENCENAME’,sorttype:’text’,editable:false,resizable:true},
{name:’SUBCONFERENCENAME’,index:’SUBCONFERENCENAME’,sorttype:’text’,editable:false,resizable:true}
],
prmNames:{page:”pageIndex”,sort:”sortCol”,order:”sortDir”,rows:”pageSize”},
postData:{method:”GetSchools”,returnFormat:”JSON”},
datatype: populateGrid,
jsonReader: {
id: “SCH_ID”,
root: function(obj){return obj.DATA.DATA;},
page: “pageIndex”,
total: function(obj){return parseInt(obj.pageCount);},
records: function(obj){return parseInt(obj.recordCount);},
cell:””
}
});
grid.jqGrid(‘navGrid’,’#ptoolbar’,{del:false,add:false,edit:false,search:false});
grid.jqGrid(‘filterToolbar’,{stringResult:true,searchOnEnter:false});
});
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top