4

How can I get the Selected Row Object of dojox.enhancedGrid ? I am using selectionMode: 'single' e.g. with Radio Buttons.

dijit.byId("gridViewWidget").selection.selectedIndex Returns the rowIndex. But how to get the rowObject of that Index ? I can get the rowNode()But What I need is value of the id column of that Row.

Its possible to travarse the HTML DOM returned by rowNode() But Is there any straight forward way ?

I am currently using dijit.byId("gridViewWidget").store._dataArray[i] and passing the returned index. Though This works it seems _dataArray is a private property. So Is it safe to use ?

Neel Basu
  • 12,638
  • 12
  • 82
  • 146

2 Answers2

5

I'm new to dojo myself, but this should be useful if not entirely correct. First of all, dojox.grid.enhancedGrid is built on top of dojox.grid.DataGrid, so check out the documentation here:

dojox.grid.DataGrid Documentation

  • grid.getItem(idx) returns the store 'item' at the given index

  • grid.selection.getSelected() returns an array of the selected items

You should be able to use either of these to get the item you want.

cнŝdk
  • 31,391
  • 7
  • 56
  • 78
Dfowj
  • 739
  • 9
  • 25
  • Hmm I've tried But there is no such method named `getItem(idx)` or `getSelected()` on the selection object. my be the selection object is different for dataGrid and enhanced grid. – Neel Basu Jun 18 '10 at 16:33
  • Hm, that could be. Like i said, im no expert... and the documentation is also misleading... best of luck! – Dfowj Jun 18 '10 at 21:29
0

Using declarative markup, you could do something like (from memory, may need tweaking to be functional):

<script type="text/javascript">
function formatThisColumn(rowIndex, rowObject) {
    if (rowObject == null) return;
    field = rowObject.i.fieldName;
    return field;
}
</script>
<div dojoType="dojo.data.ItemFileReadStore" id="store" jsid="jsonStore" url="test.json"></div>
<table dojoType="dojox.grid.EnhancedGrid" id="gridNode" jsid="grid" store="store">
<thead>
<tr>
  <th get="formatThisColumn">A Computed Column</th>
</tr>
</thead>
</table>

Note the 'formatThisColumn' function: this gets called at least once per row in the datagrid, and gets passed the index of the row (within the JSON items) and a object that contains the 'current' item (using the 'i' index). This gives you the original values from the JSON response while the datagrid is being rendered.