3

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.

2 Answers2

0

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.

Simon MᶜKenzie
  • 8,344
  • 13
  • 50
  • 77
0

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...

Tim
  • 3,576
  • 6
  • 44
  • 58