jqGrid GridUnload/GridDestroy
当我使用 $('#mygrid').jqGrid('GridUnload');
我的网格被破坏:没有寻呼机/没有标题.
When I use $('#mygrid').jqGrid('GridUnload');
my grid is destroyed: no pager/ no header.
在我发现的一个 wiki 中:
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.
我找不到 GridUnload/GridDestroy 之间的任何区别,还是我有什么问题?
I can't find any difference between GridUnload/ GridDestroy or do I something wrong?
我使用 jqGrid 3.8.
推荐答案
为了能够在页面上创建 jqGrid,你必须在页面的位置插入一个空的 <table>
元素你想在哪里看到网格.最简单的表格元素示例是 <table id="mygrid"></table>
.
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>
.
在您调用 $('#mygrid').jqGrid({...})
并且将创建列标题等网格元素.
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.
GridDestroy
方法的工作方式类似于 jQuery.remove.它删除所有属于网格的元素包含 <table>
元素.
The method GridDestroy
works like jQuery.remove. It deletes all elements which belong to the grid inclusve the <table>
element.
另一方面, The method 相关文章GridUnload
方法删除所有内容,但 空 元素保留在页面上.所以你可以在同一个地方创建新的网格.如果您需要根据不同的条件在一个地方创建不同的网格,则
GridUnload
方法非常有用.查看 旧答案 与 演示.该演示展示了如何在同一个地方动态创建两个不同的网格.如果您只是将代码中的 GridUnload
替换为 GridDestroy
,则演示将不起作用:在销毁第一个网格后,将不会在同一位置创建其他网格.
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.