Results 1 to 4 of 4

Thread: pre-select checkboxes of gridpanel of "checkboxmodel" from store

  1. #1
    Sencha User
    Join Date
    Jan 2011
    Posts
    15
    Vote Rating
    0
      0  

    Default Unanswered: pre-select checkboxes of gridpanel of "checkboxmodel" from store

    I am trying to load data from store into a gridpanel with checkboxmodel, however, it produces an error "views is undefined". What's missing here?

    Code:
    Ext.define('MyGridPanel', {
        extend: 'Ext.grid.Panel',
        alias: 'widget.myGridPanel',
        preventHeader: true,     
        store: Ext.create('StoreA',{
            autoLoad: false,
            listeners: {
                load: function() {
                }
            }
        }),
        columns: [
            { header: 'ID', dataIndex: 'id', hidden: true },
            { header: 'checked', dataIndex: 'checked', hidden: false },
            { header: 'Name',  dataIndex: 'passengerName', flex: 1 }
        ],
        selModel: new Ext.selection.CheckboxModel({
            mode: 'MULTI'
        }),
        selType: 'checkboxmodel',
        multiSelect: true,    
        loadForm: function(bookingHotelItemId) {
            var gridpanel = this;
            var store = this.store;
            this.store.load({
                method: 'get',
                url  : '/passenger!list.action',            
                callback: function(records, operation, success) {                 
                    Ext.each(records, function(item) {
                        var record = store.findRecord("id", item.data.id);
                        if (item.data.checked == "y") {
                            var record = this.getById(item.data.id);
                            gridpanel.getSelectionModel().select(record, false, false);
                        }
                    });
                },
                failure: function(form, action) {
                }
            });
        }
    });

  2. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,790
    Answers
    583
    Vote Rating
    390
      0  

    Default

    When does loadForm get called? Could you post the full stacktrace, including line numbers?

    A couple of things I notice.

    Firstly, you are putting a fully instantiated store into your define config. The store object will be put on the grid class's prototype. This means that all instances of your grid will share the same store.

    Secondly, you seem to be specifying your selection model options twice. I don't think it'll hurt but you might want to remove the duplication to avoid any confusion.

  3. #3
    Sencha User
    Join Date
    Jan 2011
    Posts
    15
    Vote Rating
    0
      0  

    Default

    after a few trials and tests, I found out that I should "check" those checkboxes after render, because after the store is loaded, the form's view has not been created yet.
    By the way, if I do not create the store over there, what's the appropriate way of doing that? I thought about using StoreManager or 'define' it somewhere or even in the constructor

    Code:
    listeners: {
            itemdblclick: function(){
            },
            afterrender: function() {
                var selectedRecords = [];
                this.store.each(function(record) {
                    if (record.data.checked == "y") {
                        selectedRecords.push(record);
                    }
                });
                this.getSelectionModel().select(selectedRecords, false, false);
            }
        },

  4. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,790
    Answers
    583
    Vote Rating
    390
      0  

    Default

    Using afterrender is a little risky. It makes 2 assumptions: the store is loaded before the grid renders and the store only loads once. I think using the refresh event might be a safer bet.

    I don't understand your question about the store.

Posting Permissions

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