PDA

View Full Version : Back end update for selected rows



billy.v8mgb
20 Jun 2013, 7:41 AM
ExtJS newbie here, started my first application yesterday. Pretty basic so far, populates a grid with the contents of a database table. I added a CheckboxSelectionModel column to select rows and added a button to the toolbar. Now I need to attach a handler to the button to spin through the checked rows and update a field in the associated database table records. I'm having trouble finding how to do this, can anyone point me to an example?

Thanks!

raj_plays
20 Jun 2013, 8:18 AM
Something like this...
Here the handler makes an Ajax call to the server side with the selected records' ids


var selections = OptionsListingGrid.selModel.getSelections();
var ids = '';


for (var i = 0; i < selections.length; i++) {

ids += selections[i].id + ',';
}



Ext.Ajax.request({
waitMsg: 'Deleting...',
url: 'RTService.asmx/delete',
params: {
ids: ids.substring(0, ids.lastIndexOf(','))
},
success: function (response) {


Ext.MessageBox.alert('Success','Campaign(s) deleted.');

},
failure: function (response) {
Ext.MessageBox.alert('Error', 'Could not connect to the database. Please Retry.');
}
});

billy.v8mgb
20 Jun 2013, 9:19 AM
Thanks! I'm trying to understand what will be the contents of the elements of the array returned by getSelections(). The documentation doesn't seem to say, the source code says selections.items, and I can't figure out what's in items. Can I expect a particular object type? What does the id attribute contain?

raj_plays
22 Jun 2013, 10:12 AM
getSelections() returns an array of Ext.data.Record objects.
Id needs to be set when you populate a store with records.