Get DataKeyName from client OnCommand event

8 posts, 0 answers
  1. rh
    rh avatar
    192 posts
    Member since:
    Jan 2007

    Posted 13 Nov 2009 Link to this post

    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?
  2. arnaud
    arnaud avatar
    105 posts
    Member since:
    Jul 2008

    Posted 14 Nov 2009 Link to this post

    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



  3. rh
    rh avatar
    192 posts
    Member since:
    Jan 2007

    Posted 14 Nov 2009 Link to this post

    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.
  4. arnaud
    arnaud avatar
    105 posts
    Member since:
    Jul 2008

    Posted 14 Nov 2009 Link to this post

    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
  5. rh
    rh avatar
    192 posts
    Member since:
    Jan 2007

    Posted 15 Nov 2009 Link to this post

    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.
  6. Nils C.
    Nils C. avatar
    41 posts
    Member since:
    Oct 2009

    Posted 09 Aug 2012 Link to this post

    Hi everyone,
    I know this post is quite old - but I'm facing the same issue right now. Has this been solved?
  7. Sonny
    Sonny avatar
    4 posts
    Member since:
    May 2014

    Posted 20 Oct 2015 Link to this post

    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.

  8. Eyup
    Admin
    Eyup avatar
    3819 posts

    Posted 23 Oct 2015 Link to this post

    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
Back to Top