jqGrid GridUnload/ GridDestroy

Scharlotte picture Scharlotte · Feb 7, 2011 · Viewed 59k times · Source

When I use $('#mygrid').jqGrid('GridUnload'); my grid is destroyed: no pager/ no header.

In a wiki I found:

The only difference to previous method is that the grid is destroyed, but the table element and pager (if any) are left ready to be used again.

I can't find any difference between GridUnload/ GridDestroy or do I something wrong?

I use jqGrid 3.8.

Answer

Oleg picture Oleg · Feb 7, 2011

To be able to create jqGrid on the page you have to insert an empty <table> element on the place of the page where you want see the grid. The simplest example of the table element is <table id="mygrid"></table>.

The empty <table> element itself will be not seen on the page till you call $('#mygrid').jqGrid({...}) and the grid elements like column headers will be created.

The method GridDestroy works like jQuery.remove. It deletes all elements which belong to the grid inclusve the <table> element.

The method GridUnload on the other hand delete all, but the empty <table> element stay on the page. So you are able to create new grid on the same place. The method GridUnload is very usefull if you need create on one place different grids depend on different conditions. Look at the old answer with the demo. The demo shows how two different grids can by dynamically created on the same place. If you would be just replace GridUnload in the code to GridDestroy the demo will be not work: after destroying of the first grid no other grids will be created on the same place.