问题
I have a SlickGrid in which the user can choose various datasets. Thus the schema can change. So when the user selects a new dataset, I need to either delete the SlickGrid and start over, or clear the existing one.
What is the proper approach? Should I just delete the DOM node? I have looked through the API and cannot find any grid level calls that appears to accomplish what I am looking to do.
thanks
回答1:
Use Data view and "OnChange()
" call following lines,
grid.invalidateAllRows();
dataView.setItems(newData, "Id");
grid.render();
If your not using dataview try this,
var data = []; \\or new array
grid.setData(data);
grid.render();
回答2:
Below code did the job for me to reset the slickgrid from javascript
dataView.beginUpdate();
dataView.getItems().length = 0;
dataView.endUpdate();
回答3:
Call:
grid.setData(<new data>)
回答4:
Any of the following can be used to add data
//add data using slickgrid object
data.splice(data.length, 1, item);
grid.setData(data);
grid.invalidateRow(data.length);
grid.render();
//add single item using data view
dataView.addItem(item);
grid.updateRowCount();
grid.invalidateRow(data.length);
grid.render();
//set all new data set in grid, using a new set of data including added on (Mutliple rows)
data.splice(data.length, 1, item);
dataView.setItems(data, 'ID');
grid.invalidateAllRows();
grid.render();
来源:https://stackoverflow.com/questions/17644478/resetting-slickgrid-for-new-data