0
votes

So if I have a gridpanel in ExtJS 4, how do I check for a value in it?

I'm building a pop-up window to add a value to the gridpanel, and I want to make sure that the value the user is trying to add to the gridpanel isn't already listed in the grid panel.

I've been searching the docs for a while and googling around and haven't found anything.

1

1 Answers

1
votes

I added the following code to the bottom of the example at http://dev.sencha.com/deploy/ext-4.0.7-gpl/examples/grid/array-grid.html

Hopefully it's a start for you, though you might have additional things to consider such as the following in order to devise the most robust solution:

  • What if the same value can occur multiple times in the grid?
  • What if the data in the grid is paginated?

CODE:

dockedItems: [{
        xtype: 'toolbar',
        items : [ {
            xtype: 'button',
            text: 'Seek Value',
            handler: function() {
        Ext.Msg.prompt('Value in Grid?', 'Search:', function(btn, text){
                if (btn == 'ok' && text){
                    var columnNames = Ext.Array.pluck(grid.columns, 'dataIndex');

                    grid.store.data.each(function(record, index) {
                        for (var i=0,n=columnNames.length; i<n; i++) {
                            var columnName = columnNames[i];

                            if (columnName) { //protects against null dataIndex using pluck above
                                if (record.get(columnName) == text) {
                                    console.log(index); //row
                                    console.log(columnName);
                                    return;
                                }
                            }
                        }
                    });
                }
        });
            }
        }],
        dock: 'bottom'
    }]