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

Getting DataKey from selected item

5 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ahrensberg
Top achievements
Rank 1
Ahrensberg asked on 21 Jan 2010, 10:56 AM
Hi all,

My MasterTable is defined by:

<MasterTableView DataKeyNames="id">  
    <Columns> 
        <telerik:GridBoundColumn HeaderText="Street" DataField="Address.Street" />                                          
        <telerik:GridBoundColumn HeaderText="HouseNumber" DataField="Address.HouseNumber" /> 
        <telerik:GridBoundColumn HeaderText="ZipCode" DataField="Address.ZipCode.Code" /> 
        <telerik:GridBoundColumn HeaderText="City" DataField="Address.ZipCode.City" /> 
    </Columns> 
</MasterTableView> 

And I want to get the id of the selected item client side. I thought that this would do the trick:

// Javascript  
var selectedItem = $find("MyGridClientID").get_masterTableView().get_selectedItems()[0];  
var selectedItemID = selectedItem.getDataKeyValue("id"); 

But this 'selectedItemID' is following null. What do I do wrong? :o/

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 Jan 2010, 11:11 AM
Hello Ahrensberg,

Try setting the ClientDataKeyNames property of the MasterTableView to the datafield of the column(id in your case).
Check out the following document which shows an example:

Thanks
Shinu.
0
Ahrensberg
Top achievements
Rank 1
answered on 21 Jan 2010, 11:30 AM
I tried to do as in the example:

var firstDataItem = $find("MyGridClientID").get_masterTableView().get_dataItems()[0];  
var keyValue = firstDataItem.getDataKeyValue("id"); 

But keyValue is still null (firstDataItem is not)... :-S
0
Ahrensberg
Top achievements
Rank 1
answered on 21 Jan 2010, 11:33 AM
DO'H! Should of course set 'ClientDataKeyNames' instead of 'DataKeyNames' - as you wrote! ;o)

Thank you! :o)
0
Martin de Ruiter
Top achievements
Rank 2
answered on 08 Oct 2012, 06:48 PM
What's the correct link to the Extracting key values client-side article?
0
Shinu
Top achievements
Rank 2
answered on 09 Oct 2012, 03:22 AM
Hi,

Here is the link.
Extracting Key Values Client-side

Thanks,
Shinu.
Tags
Grid
Asked by
Ahrensberg
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ahrensberg
Top achievements
Rank 1
Martin de Ruiter
Top achievements
Rank 2
Share this question
or