PDA

View Full Version : Saving multiple rows selected using a checkbox selection model at once.



mazhar.shaikh
10 Mar 2013, 5:41 PM
Hello,


I have a grid that uses Checkbox selection model. Under the grid, I have a Save button that has to save all the currently selected rows from the grid to my store. I know how to save a single row, but not sure about
how to save multiple rows at once that are currently selected using checkbox selection model.
Can someone guide me on how to achieve that.

Thanks

Code for controller:


// Get the selected item first
var grid = Ext.getCmp('titleSearchResultsGridPanel');
var selection = grid.getSelectionModel().getSelection();
if (selection.length > 0){
var itemStore = Ext.getStore('GeneratePicklist');
itemStore.proxy.url = MasterDataManager.globals.url + "Items/";
//itemStore.update(active);
itemStore.sync();

}
else{
//TODO: no items selected
}



Code for Store


Ext.define('PickList.store.GeneratePicklist', {
extend: 'Ext.data.Store',


requires: [
'PickList.model.GeneratePicklist'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: false,
remoteFilter: true,
remoteSort: true,
storeId: 'generatePicklist',
model: 'PickList.model.GeneratePicklist',
pageSize: 50,
proxy: {
type: 'rest',
simpleSortMode: true,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
reader: {
type: 'json',
idProperty: 'isbn',
root: 'Lines',
totalProperty: 'TotalOrders'
},
writer: {
type: 'json'
}
}
}, cfg)]);
}
});

Code for the Grid View


{ xtype: 'form',
id: 'reviewPicklistForm',
layout: {
type: 'auto'
},
title: '',
items: [
{
xtype: 'gridpanel',
height: 364,
id: 'reviewPicklistGrid',
margin: '0 0 10',
width: 1091,
title: '',
store: 'GeneratePicklist',
viewConfig: {
id: 'reviewPicklistGridview'
},
selModel: Ext.create('Ext.selection.CheckboxModel', {


}),
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'isbn',
text: 'ISBN'
},
{
xtype: 'gridcolumn',
width: 176,
dataIndex: 'titleDescription',
text: 'Title'
},
{
xtype: 'gridcolumn',
dataIndex: 'author',
text: 'Author'
},
{
xtype: 'gridcolumn',
width: 82,
dataIndex: 'format',
text: 'Format'
},
{
xtype: 'numbercolumn',
width: 44,
dataIndex: 'quantity',
text: 'Qty',
format: '0,000'
},
{
xtype: 'numbercolumn',
width: 79,
dataIndex: 'webOrderNumber',
text: 'Web Order #',
format: '0000'
},
{
xtype: 'gridcolumn',
width: 66,
dataIndex: 'floor',
text: 'Floor'
},
{
xtype: 'gridcolumn',
dataIndex: 'category',
text: 'Category'
},
{
xtype: 'numbercolumn',
width: 47,
dataIndex: 'stockOnHand',
text: 'SOH',
format: '0000'
},
{
xtype: 'datecolumn',
width: 84,
dataIndex: 'lastReceipt',
text: 'Last Receipt',
format: 'd/m/Y'
},
{
xtype: 'numbercolumn',
width: 95,
dataIndex: 'receiptQty',
text: 'Receipt Qty',
format: '0,000'
},
{
xtype: 'booleancolumn',
dataIndex: 'isParked',
flex: 1,
text: 'Park',
falseText: 'No',
trueText: 'Yes'
}
],
dockedItems: [
{
xtype: 'pagingtoolbar',
dock: 'bottom',
width: 360,
displayInfo: true,
store: 'GeneratePicklist'
}
]
},
{
xtype: 'textfield',
id: 'totalTitlesReviewTextbox',
margin: '0 0 5',
width: 208,
readOnly: true,
fieldLabel: 'Total Number of Titles',
labelWidth: 135
},
{
xtype: 'textfield',
id: 'totalOrdersReviewTextbox',
margin: '0 0 10',
width: 208,
readOnly: true,
fieldLabel: 'Total Number of Orders',
labelWidth: 135
}
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'bottom',
height: 29,
items: [
{
xtype: 'button',
id: 'selectAllNewPicklistButton',
text: 'Select All'
},
{
xtype: 'button',
id: 'clearAllNewPicklistButton',
text: 'Clear All'
},
{
width: 364
},
{
xtype: 'button',
id: 'printReviewPicklistButton',
text: 'Print Picklist'
}
]
}
]
}

mitchellsimoens
12 Mar 2013, 8:29 AM
What do you mean save? What are you doing or want to do when the save button is click?

Are you adding records to the store and when you press save you want only the selected rows to be sent and in one request?

mazhar.shaikh
12 Nov 2013, 6:08 PM
I achieved it using
BATCHACTIONS: true config on the proxy


Ext.define('MyApp.store.S1', {
extend: 'Ext.data.Store',


requires: [
'MyApp.model.S1'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: false,
storeId: 's1',
model: 'MyApp.model.S1',
proxy: {
type: 'rest',
batchActions: true,
simpleSortMode: true,
timeout: 120000,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
reader: {
type: 'json',
root: 'Lines',
totalProperty: 'TotalRecords'
},
writer: {
type: 'json'
},
listeners: {
exception: {
fn: me.onRestproxyException,
scope: me
}
}
}
}, cfg)]);
},