ktm5124
ktm5124

Reputation: 12123

Ext.grid.Panel - how to access row data

I have an Ext.grid.Panel with a listener for dblclick. It looks like this:

listeners: {
    dblclick: {
        fn : function() {

               console.log("double click event processed");
        },
        element: 'el'
    }                
}

When a row is double clicked, I would like to open a URL in a new page. In order to determine the URL, I need access to row data - either that, or to the "row" in my JSON that serves as the Panel's store. How would I access this data?

Upvotes: 0

Views: 955

Answers (1)

lontivero
lontivero

Reputation: 5275

Well, the event is itemdblclick (no dblclick). And the row is passed as an argumento to the handler.

For example, in the follow sample, when you double click on a row you can see an alert pop-up window displaying the selected Simpson name:

Ext.create('Ext.data.Store', {
    storeId:'simpsonsStore',
    fields:['name', 'email', 'phone'],
    data:{'items':[
        { 'name': 'Lisa',  "email":"[email protected]",  "phone":"555-111-1224"  },
        { 'name': 'Bart',  "email":"[email protected]",  "phone":"555-222-1234" },
        { 'name': 'Homer', "email":"[email protected]",  "phone":"555-222-1244"  },
        { 'name': 'Marge', "email":"[email protected]", "phone":"555-222-1254"  }
    ]},
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            root: 'items'
        }
    }
});

Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [
        { text: 'Name',  dataIndex: 'name' },
        { text: 'Email', dataIndex: 'email', flex: 1 },
        { text: 'Phone', dataIndex: 'phone' }
    ],
    height: 200,
    width: 400,
    listeners: {
        itemdblclick: {
           fn : function(grid, record) {
               alert(record.get('name'));
           }
        }
    },                

    renderTo: Ext.getBody()
});​

You also can see it working here: http://jsfiddle.net/lontivero/utjyd/1/

Good luck!

Upvotes: 1

Related Questions