[]
TableSheet provides the ability to inject the corresponding data from the data source in real-time without refreshing the webpage. This feature, for example, helps you to switch the data sources to a backup server in case the live server returns a connection error and many other scenarios.
To update the data source dynamically, follow the steps below:
Invoke the fromJSON method.
spread.fromJSON(spreadJson);
Update the table datasource option by wrapping the datasource as an object in Promise’s resolve method.
let myTable = spread.dataManager().tables["myTable"];
myTable.options = {
remote: {
read: function () {
return Promise.resolve(dataSource);
}
}
};
Invoke the table’s fetch method with the new reload argument. This step refreshes the datasource and calls the setDataView method with an updated data source.
myTable.fetch(true).then(function()
{
let myView = myTable.views["myView"];
let sheet = spread.getActiveSheetTab();
sheet.setDataView(myView);
});
Note: View’s fetch method and Table’s fetch method have the same new reload argument. Hence, the setDataView method helps in clearing the cache status after fetching the data view again.