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

Client Javascript Issue - getDataKeyValue null

4 Answers 480 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manny Siddiqui
Top achievements
Rank 1
Manny Siddiqui asked on 26 Jan 2010, 08:04 PM

Hi,

I have been facing the following problem.

The grid is declared as follows.

 

<

 

telerik:RadGrid ID="RadGrid1" EnableViewState="true" runat="server" GridLines="Vertical" AllowFilteringByColumn="false" AutoGenerateColumns="false" AllowPaging="true" AllowCustomPaging="true" AllowSorting="true" ShowStatusBar="true" AllowMultiRowSelection="true" Height="600px">

 

Grid columns are defined as follows; Please note the DataKeyNames property.

<
MasterTableView BorderStyle="None" BorderWidth="0" AllowCustomSorting="true" DataKeyNames="col1">
 <telerik:GridBoundColumn UniqueName="item_num" DataField="item_num" DataType="System.Int32" SortExpression="item_num"  
 HeaderText
="item number">

 

 

 

</telerik:GridBoundColumn>

 

I have multi row select enabled on the grid. After selecting multiple rows, I run the following Javascript to get the value of the data key for those rows but it returns null for

var radgrdItems = $find("<%=RadGrid1.ClientID %>");
var mtv = radgrdItems.get_masterTableView();

// Get array of GridDataItem
var selectedRows = mtv.get_selectedItems();

// Works as expected. Returns the count of selected rows.
alert(selectedRows.length);

for (var i = 0; i < selectedRows.length; i++) {
   var row = selectedRows[i];
   if (row == null)
     alert("row is null");
   else {
      // Works as expected - Returns the id
      alert("get_id()= " + row.get_id());

      // Does not work! Returns null for the get_dataItem()["item_num"]
      alert("item #=" + row.get_dataItem()["item_num"]);

      // Does not work! Returns null for the row.getDataKeyValue("col1")
      alert("col1 key value=" + row.getDataKeyValue("col1"));
   }


What am I doing wrong?

I have already looked @ http://demos.telerik.com/aspnet-ajax/grid/examples/client/keys/defaultcs.aspx page and could not find the issue in my code (may be I am missing something?)

Any help is appreciated.

Thanks,
Manny

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 Jan 2010, 08:10 PM
Hello Manny,

Your MasterTableView should look like this:
<MasterTableView 
   BorderStyle="None"
   BorderWidth="0"
   AllowCustomSorting="true"
   DataKeyNames="col1"
   ClientDataKeyNames="col1">

Please notice the ClientDataKeyNames property. I recommend you examine this help topic for more information.

Extracting key values client-side


Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Manny Siddiqui
Top achievements
Rank 1
answered on 26 Jan 2010, 08:16 PM
Thanks Daniel. That fixed the issue.
0
Erik
Top achievements
Rank 2
answered on 08 Jul 2015, 10:40 AM
All the links are broken in the post of Daniel
0
Daniel
Telerik team
answered on 09 Jul 2015, 11:50 AM
Hello Erik,

Please try the following links:
Client-side Editing
get_clientDataKeyNames()

Let me know if you need more information.

Regards,
Daniel
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
Manny Siddiqui
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Manny Siddiqui
Top achievements
Rank 1
Erik
Top achievements
Rank 2
Share this question
or