dojox.grid.DataGrid:如何从点击事件访问数据? [英] dojox.grid.DataGrid: how to access data from a click event?

查看:198
本文介绍了dojox.grid.DataGrid:如何从点击事件访问数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Dojo 1.5(包括dojox)。我有一个dojox.grid.DataGrid,其中每行代表一个用户。当我点击一行时,我想重定向到像/ users / USER_ID这样的URL。用户ID是网格中的一个字段,所以我需要在我的onRowClick回调中获取所点击的行的用户ID。



点击事件包含一个rowIndex属性,实际上,我发现其他地方发现了一个(相当老的)帖子,建议我应该可以做到:

  var row = dijit.byId('grid')。model.getRow(e.rowIndex); 
/ *(然后抓住行的第0个字段,这是用户ID。)* /

(对不起,我已经丢失了URL。)



但是我的网格对象没有模型属性。怎么了? API是否已更改? (我的网格肯定填充了数据,我可以看到,点击,按列排序等等)。



所以我现在卡住了。注意,BTW,使用rowIndex直接访问网格的底层dojo.data.ItemFileReadStore将无法正常工作。这是因为网格是可排序的,所以不能保证网格的行与商店的顺序相同。



任何提示都将深受赞赏。我希望这个问题是清楚的,足够普遍的,任何答案都可以帮助别人在我的困境中。非常感谢。

解决方案

我有一个类似的场景,我抓住了这样的价值:

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

在这种情况下,my_grid是对datagrid的引用,object_path是列我存储对象的路径。 open_link当然是我的一个自定义函数,它意味着请求一个服务器路径。



所以只需更改细节就可以适应你的情况,你应该是好的。 / p>

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.

解决方案

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.

这篇关于dojox.grid.DataGrid:如何从点击事件访问数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆