Javascript jqgrid 删除网格内的所有行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5818319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jqgrid delete all rows inside grid
提问by user590586
Is there a way to delete all rows in one function call? and not by looping through all rows and deleting row by row.
有没有办法在一个函数调用中删除所有行?而不是通过循环遍历所有行并逐行删除。
Thank's In Advance.
提前致谢。
采纳答案by Oleg
It's depend on what you exactly mean under "deleting of all rows". The method GridUnloadcould be very helpful in many cases, but it delete more as only grid contain.
这取决于您在“删除所有行”下的确切含义。方法GridUnload在许多情况下可能非常有用,但它会删除更多,因为只有网格包含。
Another method used intern in jqGrid is:
jqGrid 中使用的另一种实习方法是:
var trf = $("#list tbody:first tr:first")[0];
$("#list tbody:first").empty().append(trf);
Probably it is what you need. It delete all grid rows excepting of the first one. You can overwrite the code also as the following
可能这就是你所需要的。它删除除第一个之外的所有网格行。您也可以按如下方式覆盖代码
var myGrid = $("#list"); // the variable you probably have already somewhere
var gridBody = myGrid.children("tbody");
var firstRow = gridBody.children("tr.jqgfirstrow");
gridBody.empty().append(firstRow);
回答by Shane Courtrille
If you mean remove all rows from the grid you can just do this..
如果您的意思是从网格中删除所有行,您可以这样做..
$('#grid1').jqGrid('clearGridData');
回答by RayL
If you're going to remove all rows and insert grid data back, you may use $('#grid1').jqGrid('GridUnload');
Otherwise, you can use old answersuggested by Oleg
如果您要删除所有行并重新插入网格数据,则可以使用$('#grid1').jqGrid('GridUnload');
否则,您可以使用Oleg 建议的旧答案