2

I'm using Dojo 1.5 (including dojox). I have a dojox.grid.DataGrid where each row represents a user. When I click a row, I want to redirect to a URL like /users/USER_ID. The user ID is one of the fields in the grid, so all I need to do in my onRowClick callback is to grab the user ID for the row that was clicked.

The click event contains a rowIndex property, and, indeed, I found a (rather old) post elsewhere that suggested I should be able to do:

var row = dijit.byId('grid').model.getRow(e.rowIndex);
/* (Then grab the 0th field of the row, which is the user ID.) */

(Sorry, I've since lost the URL.)

But my grid object has no model attribute. What's up with that? Has the API changed? (My grid certainly is populated with data, which I can see, click, sort by column, et cetera).

So I'm stuck for now. Note, BTW, that it won't work to use rowIndex to directly access the grid's underlying dojo.data.ItemFileReadStore. That's because the grid is sortable, so there's no guarantee that the grid's rows will be in the same order as the store's.

Any hints would be deeply appreciated. I hope that the question is clear, and sufficiently general that any answers can help others in my predicament. Many thanks.

qdw
  • 21
  • 1
  • 4

1 Answers1

2

I have a similar scenario and I grab the value like this:

onRowClick: function(e) {
   open_link(my_grid._getItemAttr(e.rowIndex, 'object_path'));
}

In this case my_grid is a reference to the datagrid and object_path is the column where I store the path to the object. open_link is of course a custom function of mine that as it implies, requests a server path.

So just change the specifics to suite your case and you should be fine.

DanneManne
  • 21,107
  • 5
  • 57
  • 58
  • Thanks! That did the trick. Two follow-up questions: 1) Can you recommend a good source of high-level docs about how to accomplish tasks like this? I've been frustrated in my efforts to find anything above the level of Javadoc-style docs on individual APIs. dojocampus.org seems to be the best thing out there, but it's somewhat spotty. 2) In Dojo, is it considered legit to call methods named with a leading underscore? I had assumed they were private APIs. Thanks again, —qdw – qdw Dec 10 '10 at 06:28
  • 1) I agree, the docs are very spread out over lots of different sites and like you I find dojocampus to be one of the better. Though I find that www.sitepen.com/blog can be very inspiring for more advanced tasks, but it's not just dojo related topics there. And www.dojotoolkit.org/api has recently has a very nice makeover. And then of course, StackOverflow :) 2) I would not say it's totally legit. When using those functions you run into the risk that it is removed/renamed from one version to another without warning unlike the api documented methods. – DanneManne Dec 10 '10 at 07:03