简体   繁体   中英

Binding onRowClick to a DoJo datagrid (dojox.grid.DataGrid)

I have been able to get the DataGrid to do evertyhing I want except one thing. I am trying to bind the onRowClick event to a regular javascript function that will do something. I am using Dojo 1.7.2 so the connect(object,event,method) does not work. I tried using the new on(object,event...) to no avail. What am I doing wrong?

In between tags but below changeValue()[A function I wrote and known working] and the dojo.require... In other words, the very last thing in the block. I know something is wrong with the syntax of the on method but can not figure out what.

var ngrid = dijit.byId('grid');
dojo.on(ngrid,"onRowClick",changeValue());

Fix for your code; as i believe the function you'd want to bind is the actual changeValue and not what it might return, try this

dijit.byId('grid').connect("onRowClick", changeValue)

.on makes some magic to the prefixed * on *Something so try with .connect instead. Best practice is to register the listener via the object itself so it will get disconnected as grid is destroyed. Above does the call as an extension to the grid object so you should not pass the grid reference as first parameter.

This is the correct syntax with the on method

you have to remove the 'on' part of the event's name string

var ngrid = dijit.byId('grid');
dojo.on(ngrid,"rowClick",changeValue());

Similar to @mschr's answer, here is also how to get the data associated with the row clicked.

dojo.connect(grid, "onRowClick", function(e) {
     var dataItem = grid.selection.getSelected();
     // call you change method here with dataItem
});

and an example

http://jsfiddle.net/cswing/T27hv/

Assign the jsid ="mygrid" attribute to your Datagrid . Pass your jsid in the dojo connect you don't have to do dijit.byId() .

 dojo.connect(mygrid, "onRowClick", changeValue); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM