PDA

View Full Version : getting selected rows in a grid



ericwaldheim
6 Oct 2006, 11:51 AM
Is there a better way to get selected rows than this?


var row_indexes = map(function(o){ return o.rowIndex; }, mygrid.getSelectedRows());
var rows = mygrid.getDataModel().getRows(row_indexes);


Thanks,
Eric

jack.slocum
6 Oct 2006, 9:00 PM
There are a bunch of convenience functions to get the selected rows:

getSelectedRow
getSelectedRows
getSelectedRowIndex
getSelectedRowIndexes
getSelectedRowId
getSelectedRowIds

Take a look here for more info: http://www.jackslocum.com/docs/YAHOO.ext.grid.Grid.html

ericwaldheim
9 Oct 2006, 10:01 AM
I want DataModel rows. Looks like Grid.getSelectedRows returns DOM row elements. From the docs:


getSelectedRows

Array getSelectedRows()

Returns the selected rows.

Returns:
Array of DOM row elements

The Grid does an excellent job of separating me from the display, so I'm curious why I would want DOM row elements?
Wouldn't the more common need be for DataModel rows rather than DOM row elements?

thanks.

jack.slocum
9 Oct 2006, 10:58 AM
To get data model rows, you would call getRow, getRows, query, etc on the DataModel. The methods above can give you information about what is selected, then you can get those rows from your model. The data model has no clue what is selected as it is separate.

Get the selected rows from the data model:


var selected = grid.getSelectedRowIndexes();
var rows = dataModel.getRows(selected);


rows is now a multi-dimensional array with the row data for the selected rows.