[英]Empty a slickgrid in Javascript on a button click
Hello I have a slickgrid with five row , how can I empty my grid on a button click? 您好,我有一个带有五行的slickgrid,如何在单击按钮时清空网格? Thanks. 谢谢。
My grid code: 我的网格代码:
var grid;
var columns = [
{id: "title", name: "Title", field: "title"},
{id: "duration", name: "Duration", field: "duration"},
{id: "%", name: "% Complete", field: "percentComplete"},
{id: "start", name: "Start", field: "start"},
{id: "finish", name: "Finish", field: "finish"},
{id: "effort-driven", name: "Effort Driven", field: "effortDriven"}
];
var options = {
enableCellNavigation: true,
enableColumnReorder: false
};
$(function () {
var data = [];
for (var i = 0; i < 5; i++) {
data[i] = {
title: "Task " + i,
duration: "5 days",
percentComplete: Math.round(Math.random() * 100),
start: "01/01/2009",
finish: "01/05/2009",
effortDriven: (i % 5 == 0)
};
}
grid = new Slick.Grid("#myGrid", data, columns, options);
So to do what you intend to do, the following piece of code should work... Please note that I did not try it, I usually do a refresh of data instead, so try it and let me know: 因此,要做您打算做的事情,下面的代码应该可以工作...请注意,我没有尝试过,我通常会刷新数据,因此请尝试并让我知道:
// initialize the model after all the events have been hooked up
var data = null; // empty out your dataset
dataView.beginUpdate();
dataView.setItems(data);
dataView.endUpdate();
// re-render the grid
grid.updateRowCount();
grid.render();
EDIT 编辑
I just realized that you are not using a dataview object, I always use a dataview, it's easier to play with the data. 我只是意识到您没有使用dataview对象,而是始终使用dataview,因此使用数据更容易。 So without the dataview, you could instead try doing this: 因此,如果没有dataview,则可以尝试执行以下操作:
// reset the dataset
grid.setData(null, true);
// re-render the grid
grid.updateRowCount();
grid.render();
For the method documentation, see the wiki: SlickGrid grid.setData() 有关方法文档,请参见Wiki: SlickGrid grid.setData()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.