Results 1 to 3 of 3

Thread: Saving multiple rows selected using a checkbox selection model at once.

  1. #1
    Sencha User
    Join Date
    Feb 2013
    Location
    NZ
    Posts
    150
    Answers
    7
    Vote Rating
    8
      0  

    Default Answered: Saving multiple rows selected using a checkbox selection model at once.

    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:

    Code:
    // 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

    Code:
    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

    Code:
    {                            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'
                                            }
                                        ]
                                    }
                                ]
                            }

  2. I achieved it using
    BATCHACTIONS: true
    config on the proxy

    Code:
    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)]);
        },

  3. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,060
    Answers
    3976
    Vote Rating
    1389
      0  

    Default

    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?
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Feb 2013
    Location
    NZ
    Posts
    150
    Answers
    7
    Vote Rating
    8
      0  

    Default

    I achieved it using
    BATCHACTIONS: true
    config on the proxy

    Code:
    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)]);
        },

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •