点击按钮在Javascript中清空一个slickgrid

时间:2014-01-04 11:00:07

标签: javascript slickgrid

你好我有一个五行的滑板,如何在按钮点击时清空我的网格? 感谢。

我的网格代码:

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);

1 个答案:

答案 0 :(得分:0)

所以要做你想做的事情,下面的代码应该可以工作......请注意我没有尝试过,我通常会刷新数据,所以试试看,让我知道:

// 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();

修改
我刚刚意识到你没有使用数据视图对象,我总是使用数据视图,它更容易使用数据。因此,如果没有数据视图,您可以尝试这样做:

// reset the dataset
grid.setData(null, true);

// re-render the grid
grid.updateRowCount();
grid.render();

有关方法文档,请参阅wiki:SlickGrid grid.setData()