This is a migrated thread and some comments may be shown as answers.

Get DataKeyName from client OnCommand event

7 Answers 248 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rh
Top achievements
Rank 1
rh asked on 13 Nov 2009, 08:34 PM
I need to get the DataKeyName for the row that is clicked in the client javascript OnCommand event.

I was hoping I could do something like

var item = args.get_item();
var itemIndex = item.get_itemIndex();

but get_item() doesn't exist. And I can't find an documentation as to what is avaiable in the client side GridCommandEventArgs class that is passed to the OnCommand client event. Is there a way to get the DataKeyName from this event?

7 Answers, 1 is accepted

Sort by
0
arnaud
Top achievements
Rank 1
answered on 14 Nov 2009, 11:30 AM
Hi,

function OnCommand(sender, eventArgs) {
                var value = sender.get_masterTableView().get_dataItems()[0].getDataKeyValue("id_table");
                alert(value);
            }

  <telerik:RadGrid ID="RadGrid1" runat="server">
            <ClientSettings>
            <ClientEvents OnCommand="OnCommand" />
            </ClientSettings>
            <MasterTableView ClientDataKeyNames="id_table">

Regards,
Arnaud Boiselle



0
rh
Top achievements
Rank 1
answered on 14 Nov 2009, 04:12 PM
Thanks, but this code seems to only get the datakeyvalue for the first row. I need the value for the row that was clicked which is why I was trying to get a reference to the item so I could get the itemindex.
0
arnaud
Top achievements
Rank 1
answered on 14 Nov 2009, 04:23 PM
in this case you can replace :

var value = sender.get_masterTableView().get_dataItems()[0].getDataKeyValue("id_table");

by

var value = sender.get_masterTableView().get_dataItems()[eventArgs.get_commandArgument()].getDataKeyValue("id_table");

Regards,
Arnaud Boiselle
0
rh
Top achievements
Rank 1
answered on 15 Nov 2009, 04:17 PM
Hi Arnaud,

I'm pretty sure the CommandArgument doesn't automatically contain the index of the item. I could perhaps put there in the ItemDataBound event although I'm not sure how much maintenance that would be in regards to filtering, sorting, etc. Also, on this grid I'm doing client side binding so would have to review the API to make sure it is available.

I still think there *should* be a way to get the item index in the OnCommand event and am hoping there is and I'm just not seeing it in the documentation.
0
Nils C.
Top achievements
Rank 1
answered on 09 Aug 2012, 09:20 AM
Hi everyone,
I know this post is quite old - but I'm facing the same issue right now. Has this been solved?
0
Sonny
Top achievements
Rank 1
answered on 20 Oct 2015, 02:07 PM

Hello all,

Now this thread is even older. I'm dealing with this issue as well. Has there been any solution? I'm using Telerix 2014.1.403.45.

0
Eyup
Telerik team
answered on 23 Oct 2015, 08:27 AM
Hello Clarence,

The item index is contained within the args.get_commandArgument() string value. It is there, however, only when the item index has meaning: for instance - Edit, Update, Delete commands. For Sort, Filter, Page commands the arguments are different, because these actions are not associated to a single item.

I hope the clarification was helpful.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
rh
Top achievements
Rank 1
Answers by
arnaud
Top achievements
Rank 1
rh
Top achievements
Rank 1
Nils C.
Top achievements
Rank 1
Sonny
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or