Resetting SlickGrid for new data

老子叫甜甜 提交于 2019-12-12 16:04:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!