I have a list of grids that can change their data in form by end-user. Finally, I want to sync all the grids by clicking the button, then an operation is performed.
I wrote the code below:
$.when.apply(
Ext.ComponentQuery.query('grid')
.forEach(function(item) {
if (item.getXType() == "grid") {
if (item.store.getNewRecords().length > 0 || item.store.getUpdatedRecords().length > 0 || item.store.getRemovedRecords().length > 0) {
item.store.sync();
}
}
})).then(function (results) {
//do something
});
Problem is here that store.sync()
not waiting for callback.
What is the recommended way of doing this?
In ExtJs have store proxy and also Ajax request you can use both. Proxies are used by Ext. data. Store to handle the loading and saving of Ext. data.
The itemid global attribute provides microdata in the form of a unique, global identifier of an item. An itemid attribute can only be specified for an element that has both itemscope and itemtype attributes.
create('Ext. grid. Panel', { store: { fields: ['name', 'email', 'phone'], sorters: ['name', 'phone'] }, columns: [ { text: 'Name', dataIndex: 'name' }, { text: 'Email', dataIndex: 'email' } ] }); Sorting at run time is easily accomplished by simply clicking each column header.
You can look at requires as a way to tell ExtJS: "When you construct an object of this class, please make sure to dynamically load the required scripts first".
I do it with Promise
like this:
// Sync grid data if exist dirty data
Promise.all(
Ext.ComponentQuery.query('grid')
.map(grid => grid.getStore())
.filter(s => (s.getNewRecords().length + s.getUpdatedRecords().length + s.getRemovedRecords().length) > 0)
.map(s => new Promise((resolve, reject) => {
s.sync({
success: () => { resolve(); },
failure: () => { reject(); }
});
}))
).then(() => {
//do something
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With