开发者

How to add new row on top in Slickgrid?

How开发者_开发百科 to add new row on top instead of defaulted to bottom, in slickgrid dataview impelmentation also it is appreciated someone provide example of deleting a row.


Here is an example function that will work with the example 1-simple.html example..

To Add a Row at the top:

         function addRow(){
        var newRow = {title: "new Title", duration: "1 day"};
        var rowData = grid.getData();
        rowData.splice(0, 0, newRow);
        grid.setData(rowData);
        grid.render();
        grid.scrollRowIntoView(0, false);
    }

To Delete row, it is the same idea. Get the grid data collection/ slice the array to get the data out of you want to delete and then call setData and render...


Sometimes Splice doesn't work. Try the code below:

DataView.insertItem(insertBefore, item)  ///Here insertBefore can be 0
function addRow() {

    var newRow = columns,
    newId = dataView.getLength();
    newRow.id = newId + 1;

    dataView.insertItem(0, newRow);
}

and then you can call this function on button click. This really works. I have tried it myself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜