dojox.grid.DataGrid: how to access data from a click event?

删除回忆录丶 提交于 2019-12-11 03:03:52

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4396064/dojox-grid-datagrid-how-to-access-data-from-a-click-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!