jQuery 如何从剑道网格中删除所有行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17917962/
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
How to remove all rows from a Kendo grid
提问by Rikin Patel
I am using Kendo grid
.
我正在使用Kendo grid
.
I want to remove all rows from Kendo grid
using JavaScript
.
我想从Kendo grid
using 中删除所有行JavaScript
。
I removed them using a for loop but I want to find the best way to remove all rows.
我使用 for 循环删除了它们,但我想找到删除所有行的最佳方法。
回答by Rikin Patel
回答by Paul Gorbas
That doesn't really move the underlying data of the grid, it just clears the rows being displayed. If you sort the "empty" grid, all the rows reappear form the underlying data.
这并没有真正移动网格的底层数据,它只是清除正在显示的行。如果对“空”网格进行排序,则所有行都会重新出现在底层数据中。
If instead of removing your data as shown like this:
如果不是像这样删除您的数据:
dataSource.data([]);
and instead replace it with a new array of data, say called result.Data.. like this:
而是用一个新的数据数组替换它,比如称为 result.Data.. 像这样:
dataSource.data(result.Data)
you will see the data swap, but if sort or page, again the original data is shown.
您将看到数据交换,但如果排序或分页,则会再次显示原始数据。
Anyone know how to actually change the data and have the new data replace the source data of the grid?
任何人都知道如何实际更改数据并使新数据替换网格的源数据?
UPDATE: The answer is to ALSO use the setDataSource method:
更新:答案是还使用 setDataSource 方法:
var grid = $("#grid").data("kendoGrid");
var dataSource = grid.dataSource;
dataSource.data([]);//clear out old data
dataSource.data(result.Data);//add new data
grid.setDataSource(result.Data);//set the new data as the grids new datasource
dataSource.sync();//refresh grid
回答by Shafeeq
If you are working with Angualrjs, then try to follow this code:
如果您正在使用 Angualrjs,请尝试遵循以下代码:
$scope.gridData.data([]);
Where gridData
is k-data-source="gridData"
哪里gridData
是k-data-source="gridData"
回答by Mahesh
This worked fine for me.
这对我来说很好。
var grid = $("#Grid").data("kendoGrid");
var newDataSource = new kendo.data.DataSource({
data: []
});
grid.setDataSource(newDataSource);