Hi,
I am using jqgrid for loading huge table of datas, thousands of rows. But for better performance I wand to load this huge table only one time – when site is loaded, and then periodic check server for newly added records after user load this huge table, but only this new records, not all, and then merge first time loaded json object with newly loaded records.
So i modyfi grid.base.js file:
2line around 589 before this:
var p = $.extend(true,{
add this:
var updateJSON = {};
2line around 688 before this:
_index : {},
add this:
dataUpdateJSON : false,
2line around 1180 before this:
addJSONData = function(data,t, rcnt, more, adjust) {
add this:
mergeJSONData = function(data){if(ts.p.dataUpdateJSON == true){/*data = updateJSON.data;here you must write some code do merge data and updateJSON.data*/t = updateJSON.bDiv;rcnt = updateJSON.rcnt;npage = updateJSON.npage;adjust = updateJSON.adjust;lc = updateJSON.lc;pvis = updateJSON.pvis;ts.p.datatype = "json";addJSONData(data,t,rcnt,npage>1,adjust);if(lc) { lc.call(ts,data); }if (pvis) { ts.grid.populateVisible(); }if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}data=null;endReq();}},
2line around 1630 (after edit previous it can by different) before this:
if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
add this:
if(ts.p.dataUpdateJSON === true) { updateJSON.data = data;updateJSON.bDiv = ts.grid.bDiv;updateJSON.rcnt = rcnt;updateJSON.npage = npage;updateJSON.adjust = adjust;if(lc) { updateJSON.lc = lc; };if(pvis) { updateJSON.pvis = pvis;};}
Ok, adding done, now edit your setup:
in your jqgrid set up new option “dataUpdateJSON” to true – default is false; true enable this little trick
dataUpdateJSON: true,
set up option loadComplete to function witch will call your custom reload grid function, example: reload_grid();
sample:
var grid_reload;
var grid_reload_time = 3000;
function reload_grid()
{
clearInterval(grid_reload);
grid_reload = setInterval(function()
{
var mygrid = jQuery(“#grid”)[0];
$.ajax( url:”your ajax url”,
type:”POST”,
dataType: “json” ,
data: “your data to server”,
success:function(data,st)
{
mygrid.mergeJSONData(data);
});
},grid_reload_time);
};
WARNING: I test this only with my configuration:
loadonce: true,
rowTotal: -1,
datatype: “json”,
and for now I dont have writed script code for merge two datas objects, but you can write yourself. I will post one ASAP.
So i hope that this is good idea.
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top