问题
Any ideas why multiple calls to a function that does the following
grid.jqGrid('GridUnload');
createGrid();
Will only create the grid every other time, but ...
The following will work everytime it is called:
grid.jqGrid('GridUnload');
setTimeout(createGrid, 1000);
回答1:
You don't included the code of createGrid so I can only guess. One possible reason is that you use grid variable inside. If you use GridUnload the old <table> element will be deleted and another one will be created on the same place. So you should reset the value of grid after call of GridUnload:
var gridId = grid[0].id; // or grid.attr('id');
grid.jqGrid('GridUnload');
grid = $('#' + $.jgrid.jqID(gridId)); // or just $('#' + gridId);
createGrid();
The method $.jgrid.jqID you have to use only if the id of the grid can hold some meta-character.
来源:https://stackoverflow.com/questions/9472409/consecutive-gridunload-creategrid-not-working