Howard Grimberg
Howard Grimberg

Reputation: 2188

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());

Upvotes: 0

Views: 5905

Answers (4)

jbduzan
jbduzan

Reputation: 1126

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());

Upvotes: 1

BOSS
BOSS

Reputation: 2951

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); 

Upvotes: 0

Craig Swing
Craig Swing

Reputation: 8162

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/

Upvotes: 0

mschr
mschr

Reputation: 8641

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.

Upvotes: 2

Related Questions