Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a row using javascript in SlickGrid

I am trying to add a row to a slick grid on my page using javascript. The way I am able to do it now is by using the following code. I was just wondering if there was a better way to do the same.

....

//data is the array which was used to populate the SlickGrid
data.push({name:'Finish scanning the slickgrid js', complete:false}); 
grid.setData(data);
grid.render();

....
like image 773
Khaja Minhajuddin Avatar asked Jun 21 '10 17:06

Khaja Minhajuddin


2 Answers

This is the preferred way.

data.push({...});
grid.updateRowCount();
grid.render();

Calling .setData() forced the grid to re-render everything. By calling updateRowCount() you are notifying the grid the number of the rows have changed and that it needs to render what has been added or removed only.

like image 149
Tin Avatar answered Sep 23 '22 11:09

Tin


Here is what I've been used for adding new row with Button

function add_new_row(){
  item = {"id": (Math.round(Math.random()*-10000))
  //you can add another fields to fill default data on Adding new row
  };
  data_view.insertItem(0, item);
}
like image 31
HeiN Avatar answered Sep 20 '22 11:09

HeiN