2

我想将数据添加到 SlickGrid 中的 DataView 并且我有一个代码:

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"}
             ];    

$(document).ready(function() {
        for (var i = 0; i < 200; i++) {
              data[i] = {
                id: "id_" + 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)
              };
            }

        dataView = new Slick.Data.DataView({ inlineFilters: true });
        grid = new Slick.Grid("#myGrid", dataView, columns, options);
        dataView.beginUpdate();
        dataView.setItems(data);
        dataView.setFilter(filter);
        dataView.endUpdate();
    });

但是我只看到滚动条和列标题,但我没有看到任何数据,为什么?

4

2 回答 2

1

试试这个,

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"}
             ];    

$(document).ready(function() {
        for (var i = 0; i < 200; i++) {
              data[i] = {
                id: "id_" + 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)
              };
            }

        dataView = new Slick.Data.DataView({ inlineFilters: true });
        grid = new Slick.Grid("#myGrid", dataView, columns, options);
        dataView.beginUpdate();
        dataView.setItems(data);
        dataView.setFilter(filter);
        dataView.endUpdate();
        dataView.render(); //You missed this rendering part. this should work now.
    });
于 2012-11-02T09:52:15.017 回答
1

试试这个

var data = [];
var options = {};
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"}
     ];    

$(document).ready(function() {
    for (var i = 0; i < 200; i++) {
        data[i] = {
            id: "id_" + 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)
        };
    }

    dataView = new Slick.Data.DataView({ inlineFilters: true });
    dataView.beginUpdate();
    dataView.setItems(data);
    dataView.endUpdate();

    grid = new Slick.Grid("#myGrid", dataView, columns, options);
});
于 2013-10-11T02:48:01.980 回答