I have a grid worth of data coming from 2 different data sources that I smash together on the server side and send to the grid. Data from one of my sources is fine (ish... it is pretty slow too), data from the other source is brutally slow. So I want to send all of the data from source one and the first page worth of data from source 2 to the grid on page load, and then use JQuery/ajax to do a deferred load on the remaining data in the background.
I do not want to do an AJAX call per page because data source 1 isn't fast enough for that.
Since the second data source is so slow, I am chunking the unpopulated data into page sized chunks (blocks of 10) and letting the async goodness do its thing. I can do the ajax and get the supplemental data without a problem. I just can't seem to get the grid to respect the updated data. I can't replace the whole datasource's data set at once because we are doing this all async and we will have data pouring in all willy nilly and we don't want to have potential over writes. So we have to update it per row.
const fieldsToUpdate = ["field1", "field2", "field3", "field4"];
$.ajax({
.... blah blah blah ....
success: function(responseData) {
const accounts = responseData.Data.AccountList;
for (let idx = 0; idx < accounts.length; idx++) {
const curAccount = accounts[idx];
const dataItem = theGrid.dataSource.get(curAccount.AccountNumber);
if (dataItem) {
console.log(`Deferred data load for: ${curAccount.AccountNumber}`);
for (let propIdx = 0; propIdx < fieldsToUpdate.length; propIdx++) {
const key = fieldsToUpdate[propIdx];
// because the set method will ignore anything that isn't marked as 'editable' and I don't care about that
let hasEdit = false;
if (dataItem.fields[key].hasOwnProperty("editable")) {
dataItem.fields[key].editable = hasEdit = true;
}
// actually set the value
dataItem.set(key, curAccount[key]);
// set it back to whatever it was
if (hasEdit) {
dataItem.fields[key].editable = false;
}
}
// we don't care
dataItem.dirtyFields = {};
dataItem.dirty = false;
}
}
}
});
So the above kinda sorta works. It will display the right data until you attempt to move to a different page. Then it looses it mind and the data reverts back to what it was originally (unset) and the paging breaks and the grid just stops working all together. There are no errors visible in the console.
What is the proper way to update individual rows of data in a grid that may or may not be visible on the current page of the grid?