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

[Solved] Accessing DataKeys from javascript

8 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sushruth
Top achievements
Rank 1
Sushruth asked on 21 Jul 2011, 09:56 AM
Hello, 

i am using MVC grid  to bind to a datatable  in the serverside and then have setup ajax binding for sorting/grouping etc.
Now when a row is selected i need to get the asscoicated datakey with the row in  rowselected event . How would i do that ?

I tried adding a hidden column to store the keys, but on subsequent ajax requests( i.e when sorting  ) the key column automatically become visible. 

A  solution to fix either one of the problem would save  me a lot of time ..

 thanks
sush

8 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 21 Jul 2011, 10:17 AM
Hello Sushruth,

Hidden columns should appear last because of a IE rendering bug.

 If you don't want to use hidden columns you can use the dataItem JavaScript method:

function onSelect(e) {
 var grid = $(this).data("tGrid");

 var dataItem = grid.dataItem($(e.row));

 var key = dataItem.MyDataKeyProperty;
}

Regards,
Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Sushruth
Top achievements
Rank 1
answered on 21 Jul 2011, 05:50 PM
I get the following error message in the chrome
TypeError: Cannot read property '1' of undefined


In fire Bug:
this.data is undefined
When i execute the   var dataItem = grid.dataItem($(e.row));
Look like the datakey does not get sent to the client for some reason.

here is  my serverside code

// 'dt' is of datatable type

 @(Html.Telerik().Grid(dt)
.Name(gridName)
.Columns(columns =>
  {
   columns.LoadSettings(visualizerConfiguration.Columns); 
  })
  .DataKeys(keys => keys.Add(visualizerConfiguration.Columns[0].Member))
  .RowAction(row =>
  {
   if (row.Index == 0)
   {
    row.Selected = true;
   }

  })
   .DataBinding(bind => bind.Ajax().Select("_GridAjaxSelection", "GenericVisualizer", new { gridId = gridName, key=nodeId}))
.Scrollable(scrolling => scrolling.Enabled(true))
.Selectable()
.Filterable()
.Sortable()
.Groupable()
.Reorderable(t => t.Columns(true))
.Resizable(t => t.Columns(true))
.Footer(true)
.Pageable(pa => pa.PageSize(1000).Enabled(true))
.ClientEvents(events => events.OnRowSelect(gridRowSelectFunction)))

do you see anything wrong with it ?

0
Sushruth
Top achievements
Rank 1
answered on 21 Jul 2011, 10:28 PM
Created a sample to project replicate the issue.
Click on any row it executes the js.
0
Accepted
Atanas Korchev
Telerik team
answered on 22 Jul 2011, 07:25 AM
Hello Sushruth,

 This occurs because the dataItem grid works only for ajax bound grids. Your grid is initially bound server side.

Also you seem to have taken my example literally. Your model does not contain a property named MyDataKeyProperty. Of course you should use a property from your mode which exists e.g. "Path".

I have fixed your project and you can find it attached.

Regards,
Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Sushruth
Top achievements
Rank 1
answered on 22 Jul 2011, 10:42 AM
Thanks Atanas,

I also saw that the Filter fucntionality seems to have lost when we bind to datatable . is there anyway we could achieve that.?

-Sush

0
Accepted
Rosen
Telerik team
answered on 25 Jul 2011, 07:35 AM
Hello Sushruth,

Please set the data types for columns and see if this helps:

columns.Bound(typeof(int), "Path");
columns.Bound(typeof(string), "ObjectClass");


Regards,
Rosen
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Sushruth
Top achievements
Rank 1
answered on 25 Jul 2011, 09:05 AM

In my application i am loading the columsettings using GridColumFactory::LoadSetting method

 
i.e   @(Html.Telerik().Grid(dataTable)    
 .Name(gridName)     
.Columns(columns =>         
    {             columns.LoadSettings(visualizerConfiguration.Columns);       
       })

So there isnt a property to specify the "type" of the column in GridColumnSettings Class,
So how could we get the filter option working properly in this case ?
0
Rosen
Telerik team
answered on 25 Jul 2011, 11:08 AM
Hi Sushruth,

 I'm afraid that currently setting the memberType through ColumnSettings is not supported. However, we have managed to add such functionality and I'm attaching an internal build which contains it.

Regards,
Rosen
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Sushruth
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Sushruth
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or