PDA

View Full Version : Get selected cell content from Grid panel



suryanarendra
4 May 2012, 9:15 AM
Hi,

I am using selType: 'cellmodel' in grid panel and listening to the event
select: function(model,record,row,coln,eopts). When user selects cell this event is getting fired and am getting row number and column number from it. But I would like to get content within cell to form an URL. Can somebody help me how can I get this.

CasualGamer
4 May 2012, 2:16 PM
While admittedly, this is not the greatest solution, I was able to get the text value of a cell by listening to the cellclick event.


Ext.create('Ext.grid.Panel', {
...
viewConfig: {
listeners: {
cellclick: function(table, td, columnIndex, record, tr, rowIndex, e) {
console.log(td.innerText);
}
}
}
...
}

Satakshi
5 May 2012, 11:37 PM
select (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.panel.Table-event-select)( Ext.selection.RowModel (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.selection.RowModel) this, Ext.data.Model (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.data.Model) record, Number (http://docs.sencha.com/ext-js/4-1/#%21/api/Number) index, Object (http://docs.sencha.com/ext-js/4-1/#%21/api/Object) eOpts )


record holds the selected row object.
just use
record.get('/*fieldName*/') to get particular cell's value of the selected row.

CasualGamer
7 May 2012, 6:14 AM
@Satakshi,

How do you tell which cell was clicked using the select event? That was the first thing I tried, but if the columns are rearranged, can you still know which fieldName was clicked based on the column index?

suryanarendra
7 May 2012, 5:03 PM
Thanks @Casual Gamer and @Satakshi

By using below code I was able to get selected cell text.

listeners:{
cellClick:function (view, element, colnIndex, record) {
console.log(element.textContent);
}
}

But I would like to know if the same can be achieved by using select function.

@Satakshi: I am trying to mimic excel sheet on UI and I can't use column headers.