JavaScript API Reference/Ab.grid.ReportGrid object

getSelectedRows()

Returns an array of JS objects containing selected grid rows, containing visible fields and primary keys.

Each data row JS object contains:

  • formatted visible field values ( dataRow['project.status'] )
  • unformatted visible field values ( dataRow['project.status.raw'] )
  • primary key values, even if the report does not display any of the primary key values( dataRow['project.project_id.key'] )
  • reference to the parent report grid object


Because of this last reference, you should never pass data row objects directly to the toJSON() function. If you need to serialize data rows to JSON format, you will need to create new objects and copy data values from data row objects into new objects – then you can pass new objects to the toJSON() function.

Note that a raw value is only stored and is only accessible if the field value has been formatted

Returns: JS array containing JS objects containing names and values:

[
{name_1: value_1, name_2: value_2, ...},
{name_1: value_1, name_2: value_2, ...}
]

Parameters: none

Example:

Get selected rows:

var selectedRows = this.grid.getSelectedRows();
for (var i = 0; i < selectedRows.length; i++) {
var dataRow = selectedRows[i];

// data row objects reference parent grid control
// you should never pass data row objects to toJSON()
// to serialize data rows to JSON, create new objects:

var dataRowCopy = new Object();
dataRowCopy['project.project_id'] =
dataRow['project.project_id'];
dataRowCopy['project.status'] =
dataRow['project.status'];
alert(toJSON(dataRowCopy));
}