Forum


14:51

07/04/2009

Hello,
I am new to jqGrid and I wonder how data are manage by the system.
I would like to know if jqGrid use the data return by the server and saved in the client cache (responseText) or if it use the Mydata provided to the addJSONData (e.g. mygrid.addJSONData(JSON.parse(Mydata )).
I will try to explain my problem better. Actually, I make an ajax call to get the data from a server (json) and that's working. But, I need to make some change in the data received before displaying them because they are not in the json format. Is it possible ? if yes, how can I do that, please ?
Actually, I succed to display a blank table with the pager almost well configured. I meand, everything is all right in the pager but the actual page is set to “0″ instead of “1″.
I don't get error in firebug so things looks ok… So, I don't understand why that's not working.
Can anyone help me ?
Here my code :
// We use a document ready jquery function.
jQuery(document).ready(function(){
gridimgpath = 'themes/sand/images';
jQuery("#list2").jqGrid({
datatype : function(postdata) {
jQuery.ajax({
url:'exemple.CFC?method=GetData',
data:postdata,
dataType:"any",
error: function(msg){ sDumper( "Error !: " + msg );},
complete: function(postdata){
// Update the data return by the server
responseText=... my code to change data return from server ...
// Trim the result
responseText=jQuery.trim(responseText);
var mygrid = jQuery("#list2")[0];
var myjsongrid = eval("responseText");
stuff = JSON.parse(myjsongrid);
// Populate the grid
mygrid.addJSONData(stuff);
//$("#list2")[0].addJSONData(JSON.parse(myjsongrid));
myjsongrid = null;
responseText =null;
sDumper(stuff);
}
});
},
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:55},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name asc, invdate', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false} ],
rowNum:10,
rowList:[10,20,30],
imgpath: gridimgpath,
pager: jQuery('#pager2'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
jsonReader: {
root: "ROWS",
page: "PAGE",
total: "total",
records: "records",
cell: "",
repeatitems: false,
id: "ID"
},
caption:"JSON Example" })
});
</script>
16:52

07/04/2009

I have found my mistake ! I used Uppercase in the code as fallow :
jsonReader: {
root: “ROWS”,
page: “PAGE”,
total: “total”,
records: “records”,
cell: “”,
repeatitems: false,
id: “ID”
},
I have the previous code by rewriting using lowercase. Now, that looks working ..
Here you find the working code :
// We use a document ready jquery function.
jQuery(document).ready(function(){
gridimgpath = 'themes/sand/images';
jQuery("#list2").jqGrid({
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:55},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name asc, invdate', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false} ],
rowNum:10,
rowList:[10,20,30],
imgpath: gridimgpath,
pager: jQuery('#pager2'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
id: "ID"
},//end jsonReader
caption:"JSON Example",
datatype : function(postdata) {
jQuery.ajax({
url:'exemple.CFC?method=GetData2',
data:postdata,
dataType:"local",
error: function(msg){ sDumper( "Error !: " + msg );},
complete: function(postdata){
// Update the data return by the server
responseText= [... personnal code to change data received from postdata.responseText ...]
// Trim the result
responseText=jQuery.trim(responseText);
var myjsongrid = eval("responseText");
var stuff = JSON.parse(myjsongrid);
var mygrid = jQuery("#list2")[0];
// Populate the grid
jQuery("#list2")[0].addJSONData(stuff);
//$("#list2")[0].addJSONData(JSON.parse(myjsongrid));
myjsongrid = null;
responseText =null;
stuff =null;
}// end complete
});// end ajax
},// end datatype
})// end jqgrid
}); // end ready
</script>
Most Users Ever Online: 715
Currently Online:
61 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66