最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add data to a SlickGrid DataView? - Stack Overflow

programmeradmin1浏览0评论

I'm trying to follow the simple example of using a DataView with the SlickGrid jQuery plugin. However I can't work out how the data is added to the DataView.

This are the relevant bits of the source:

var dataView;
var grid;
var data = [];
...
$(function() {
    // prepare the data
    for (var i=0; i<50000; i++) {
        var d = (data[i] = {});
        d["id"] = "id_" + i;
        ... add data to d
    }
    dataView = new Slick.Data.DataView();
    grid = new Slick.Grid("#myGrid", dataView, columns, options);

So the grid is now set up, but how does data get bound to it? I can't see anywhere in the example where it is added, and so I don't know how to add my own data.

Thanks!

I'm trying to follow the simple example of using a DataView with the SlickGrid jQuery plugin. However I can't work out how the data is added to the DataView.

This are the relevant bits of the source:

var dataView;
var grid;
var data = [];
...
$(function() {
    // prepare the data
    for (var i=0; i<50000; i++) {
        var d = (data[i] = {});
        d["id"] = "id_" + i;
        ... add data to d
    }
    dataView = new Slick.Data.DataView();
    grid = new Slick.Grid("#myGrid", dataView, columns, options);

So the grid is now set up, but how does data get bound to it? I can't see anywhere in the example where it is added, and so I don't know how to add my own data.

Thanks!

Share Improve this question asked Jan 19, 2012 at 20:50 RichardRichard 33k30 gold badges111 silver badges146 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Look further down in the source of the example - you'll find the following lines:

// initialize the model after all the events have been hooked up
dataView.beginUpdate();
dataView.setItems(data);

That's where the dataView's items are being set to the data in the data[] array.

I just downloaded a new version today. Mine shows

  $(function () {
var data = [];
for (var i = 1; i < 12; 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);

})

the data array is were you stick the data.

发布评论

评论列表(0)

  1. 暂无评论