Reputation: 4200
function clearJqGrid()
{
// get IDs of all the rows of jqGrid
var rowIds = $('#messages').jqGrid('getDataIDs');
// iterate through the rows and delete each of them
for(var i=0,len=rowIds.length;i<len;i++)
{
var currRow = rowIds[i];
$('#messages').jqGrid('delRowData', currRow);
}
}
So I run this every singe time BEFORE i make an AJAX call to fill this grid. However, if you then go up and sort one of the columns, the grid is then bringing back all the old messages that were in it from the previous fill. Without sorting, you only see the ones that should be there.
Is the Jqgrid caching its entries when it shouldn't be? Should my clearJqGrid()
method be something else? I just made it this because I found it online, but do any of you have a better one?
Thanks!
Upvotes: 1
Views: 1057
Reputation: 221997
The most effective way to remove all local data from the grid could be the code:
// get DOM element of the table
var myGridDomNode = $('#messages')[0];
// delete internal local grid data
myGridDomNode.p.data = [];
myGridDomNode.p._index = {};
// delete all grid contain excepting the first dummy invisible row
var trf = $("tbody:first tr:first",myGridDomNode)[0]; // save first row
$("tbody:first",myGridDomNode).empty().append(trf);
In other situations the GridUnload()
can be effective used which destroy additionally the column headers, pager and all grid elements. So to display the grid one more time you will need recreate it.
In the most cases you don't need delete the grid contain. After the ajax call will be completed the jqGrid will delete the grid contain itself. Only if you switch manually the datatype of grid from dytatype:'json'
to dytatype:'local'
and back you can need to do this.
Upvotes: 3