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

[Solved] Client Side Select with AJAX and DataKey

2 Answers 187 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.
John Goode
Top achievements
Rank 1
John Goode asked on 23 Mar 2011, 09:07 PM
How do you get the DataKey values using Client Side Selection and binding using AJAX?

function onRowSelected(e) {
            var grid = $(e.row).parents('#CustomerSites').data('tGrid');
            var data = grid.data[$(grid.$tbody[0].rows).index(e.row)];
            var id;
            for (x in grid.dataKeys)
                id = data[x];  
            alert(id);
  }

id is always undefined!!!!

Is this not supported for AJAX binding? I don't want to be forced to display Primary key values in the grid.

John

2 Answers, 1 is accepted

Sort by
0
Pak
Top achievements
Rank 1
answered on 30 Mar 2011, 06:42 AM

Hi John

I'm not sure if this is the best way of doing it, but it is how I do it (with the assumption that you know which one is your primary key). In the example below, SelectionID is the primary key of the row selected. 

 

function onRowSelected(e)
{
    var selectionGrid = $('#XXXXSelectionList').data('tGrid');
    var key = selectionGrid.data[e.row.rowIndex - 1].SelectionID;
}

 

 

 

 

 

It would be nice that there is an API to get the DataKeys that we register in the grid (maybe there is one which I couldn't find from the documentation).

Cheers
Pak

 

0
Steve
Top achievements
Rank 1
answered on 31 Mar 2011, 03:00 AM
Hi John,
I think you want to get the class that is the outter grid, where as looks like you might be trying to get the id of the grid.
So change this;
 var grid = $(e.row).parents('#CustomerSites').data('tGrid');

To this
 var grid = $(e.row).parents('.t-grid').data('tGrid');

I use similar methodology with Ajax and this is how I get the id.

Hope that helps.
Steve
Tags
Grid
Asked by
John Goode
Top achievements
Rank 1
Answers by
Pak
Top achievements
Rank 1
Steve
Top achievements
Rank 1
Share this question
or