Results 1 to 3 of 3

Thread: Grid scroll to group headers

  1. #1
    Sencha User
    Join Date
    Apr 2007
    Posts
    70
    Vote Rating
    0
      0  

    Default Unanswered: Grid scroll to group headers

    I have a grouped grid with a lot of rows. I would like to add a button to the grid's toolbar which allows the user to automatically scroll to any of the grid's grouped headers. So if group A is visible, and group B is not, a button would automatically scroll the grid to the location of group B in the grid.

    I know of the view's focusRow() function, I just don't know how to use it in this context. Thanks!

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,388
    Answers
    716
    Vote Rating
    499
      0  

    Default

    You should be able to use select to select the index of the 1st item in a group.

    Code:
    grid.getSelectionModel().select(2);
    You will need to determine the index.

    Scott.

  3. #3
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,154
    Answers
    501
    Vote Rating
    247
      0  

    Default

    See if this is kinda what you're looking for. Probably a little hacky, but seemed to work (did the focusRow twice since if the group is collapsed it expands the group, but does not focus the row and if it's expanded it focuses the row).

    Code:
    var store = Ext.create('Ext.data.Store', {
        storeId:'employeeStore',
        fields:['name', 'seniority', 'department'],
        groupField: 'department',
        data: {'employees':[
            { "name": "Michael Scott",  "seniority": 7, "department": "Management" },
            { "name": "Andy Bernard",  "seniority": 7, "department": "Management" },
            { "name": "Dwight Schrute", "seniority": 2, "department": "Sales" },
            { "name": "Jim Halpert",    "seniority": 3, "department": "Sales" },
            { "name": "Kevin Malone",   "seniority": 4, "department": "Accounting" },
            { "name": "Angela Martin",  "seniority": 5, "department": "Accounting" },
            { "name": "Oscar Martinez",  "seniority": 5, "department": "Accounting" }
        ]},
        proxy: {
            type: 'memory',
            reader: {
                type: 'json',
                root: 'employees'
            }
        }
    });
    
    
    Ext.create('Ext.grid.Panel', {
        title: 'Employees',
        store: Ext.data.StoreManager.lookup('employeeStore'),
        columns: [
            { text: 'Name',     dataIndex: 'name' },
            { text: 'Seniority', dataIndex: 'seniority' }
        ],
        features: [{ftype:'grouping'}],
        width: 200,
        height: 275,
        renderTo: Ext.getBody()
        , dockedItems: [{
            xtype: 'toolbar'
            , dock: 'top'
            , items: [{
                text: 'Sales'
                , handler: function (btn) {
                    var grid = btn.up('gridpanel');
                    grid.getView().focusRow(grid.store.findRecord(grid.store.groupField, btn.text));
                    grid.getView().focusRow(grid.store.findRecord(grid.store.groupField, btn.text));
                }
            }]
        }]
    });

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
  •