After adding record to a Store via client side code the GridPanel doesn't know that the row exists.

  1. #1

    After adding record to a Store via client side code the GridPanel doesn't know that the row exists.

    Hi there, if I add a record to the GridPanel using this code:

    grid.getStore().add(...
    Then click on that newly added row and try to read the index using:

    grid.getSelectionModel().selected.items[0].index
    It won't work, it returns undefined, reloading the store fixes that but defeats the purpose.

    The GridPanel doesn't know the row index but it knows that it exists and the data is there, this confirms it:

    grid.getSelectionModel().selected.items[0].data
    Any hints?
    Thanks
  2. #2
    Maybe you need to refresh view or use insert instead?

    This is how I add a row into a gridpanel that has editingPlugin and a combo.
    Maybe it will be useful...
    var addRow = function (grid, combo) {
        grid.editingPlugin.completeEdit();
        grid.editingPlugin.cancelEdit(); //completeedit will not close editing window if validation fails
        grid.getSelectionModel().clearSelections();
    
        var newRow = Ext.ModelManager.create({
            Percent: 0,
            SomeFlag: false,
            SomeID: null,
            Description: 'Some Description'
        }, 'MyModel');
    
        var insertIndex = grid.store.getCount();
        grid.store.insert(insertIndex, newRow);
        grid.getView().refresh();
        grid.editingPlugin.startEdit(insertIndex, 0);
        combo.focus();
    };
    Why exactly do you need index?
    For example if you need to remove a selection's row or rows, you really don't need its index.
    This code removes all selected rows that has a data flag of Required = false.
    var removeRow = function (grid) {
        grid.editingPlugin.completeEdit();
        grid.editingPlugin.cancelEdit(); //completeedit will not close editing window if validation fails
    
        var selected = grid.getSelectionModel().getSelection();
    
        for (var i = 0, rec; i < selected.length; i++) {
            rec = selected[i];
            if (rec.data.Required === false) {
                grid.store.remove(rec);
            }
        }
    
        grid.getView().refresh();
    };
    Last edited by ltctech; Apr 25, 2013 at 11:01 PM.

Similar Threads

  1. Replies: 2
    Last Post: Dec 29, 2011, 10:05 PM
  2. Replies: 1
    Last Post: Nov 18, 2011, 5:29 PM
  3. Replies: 1
    Last Post: Dec 01, 2010, 5:14 PM
  4. [CLOSED] detect new store record on client side
    By pschojer in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 14, 2009, 8:42 AM
  5. [CLOSED] Adding a new Store Record - Not a Record object
    By Steve in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: May 15, 2009, 7:40 AM

Posting Permissions