PDA

View Full Version : CheckboxSelectionModel rowselect - obtain row data - help request



dechambers
1 Jan 2011, 3:49 PM
Hi all,

I would like to throw out a request for a bit of help with the CheckBoxSelectionModel used with data grids ( Ext JS Lib 3.3.0 )

My grid renders nicely, all of the rows have checkboxes that I can select easily enough but try as I might I am unable to obtain the row data from the grid. Here is what my listener does:



var sm = new Ext.grid.CheckboxSelectionModel({

listeners:{
rowselect : function( selectionModel, rowIndex, record){

var selectedRows = selectionModel.getSelections();

if( selectedRows.length > 0){
alert('Success! ' + rowIndex + ' ' + record );

}
}
})



When I select one of the rows & trigger the alert the string & rowIndex show but record returns as [Object object] when what I'd really like is the 2 pieces of column data.

Ok, so it's probably not that complicated but I am weak in javascript & weaker still in Ext JS.

Anyone able to point me in the right direction - I'd be most grateful.

Many thanks,
Darren

skirtle
1 Jan 2011, 4:52 PM
[Object object] is what you get when you try to concatenate most objects with strings.

record is an Ext.data.Record and you can get the data out using the get() method. e.g.:


var name = record.get('name');Similarly, your selectedRows variable will be an array of Ext.data.Records. Whereas record will correspond to the row that has just been selected, selectedRows will contain all of the records for the rows that are currently selected.

alert() is only suitable for very basic debugging. You'd probably find it easier to install Firebug and use console.log() and console.dir(). e.g. Try:


console.dir(record);

dechambers
1 Jan 2011, 5:13 PM
Thank you Skirtle, you sorted me out & saved my sanity.

All the best,
Darren