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

OnRowSelected - DataItem

8 Answers 340 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.
Jay
Top achievements
Rank 1
Jay asked on 29 Apr 2010, 12:49 PM
I can't seem to find a consistent way to get information from the currently selected row.  The code I see in the demo, and being used here in the forums is:

var id = e.row.cells[#].innerHTML;


But that simply doesn't fly when you're using a groupable grid.  As soon as you group any columns, the indexes start moving around.  I'd much rather see something like:  

var id = e.dataItem.ID; 

Any suggestions?

-Jeff

8 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 30 Apr 2010, 08:31 AM
Hello Jeff Sheldon,

Since the dataItem is currently available only in the rowDataBound event I can suggest the following:

var id = e.row.cells[grid.groups.length + cellIndex].innerHTML;

If you are using editing you can use the following JavaScript function:

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

We will make it always available (not just when editing is enabled) in the next release.

Regards,
Atanas Korchev
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Rafael
Top achievements
Rank 1
answered on 17 Sep 2010, 10:23 AM
Atanas, could you please to help with code to color by condition a row in nested view (master/detail grid) ?
I got undefined for e.row 
This is a bound function for nested grid

 function project_OnDataBound(e) {
            var grid = $(this).data('tGrid');
            $.each(grid.data, function (i, val) {
                var probability = grid.data[i].Probability;
                if (probability <= 50) {
                    e.row.style.color = "red";
                }
                if (probability > 50 && probability <= 80) {
                    e.row.style.color = "yellow";
                }
                if (probability > 80 && probability <= 99) {
                    e.row.style.color = "lightgreen";
                }
            });
        }
0
Diiimo
Top achievements
Rank 1
answered on 29 Sep 2010, 07:13 AM

Hello,

is the dataItem now available? please, could you provide a sample?

Regards,
Timo

0
Atanas Korchev
Telerik team
answered on 29 Sep 2010, 07:34 AM
Hi Timo,

 DataItem is not available in OnRowSelect and probably will never be available. You can use the dataItem function to retrieve the dataItem associated with a particular row at any moment:

function onRowSelect(e) {
    var grid = $(this).data('tGrid');
    var dataItem = grid.dataItem(e.row);
}

Regards,
Atanas Korchev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Diiimo
Top achievements
Rank 1
answered on 29 Sep 2010, 08:38 AM

Hello,

it works for AjaxBinding. Is there a way to do this with ServerBinding?

Regards,
Timo

0
Atanas Korchev
Telerik team
answered on 29 Sep 2010, 08:39 AM
Hello Timo,

JavaScript DataItem is not available in server binding. You can use a hidden column instead.

Regards,
Atanas Korchev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Rafael
Top achievements
Rank 1
answered on 29 Sep 2010, 09:33 AM
hi Timo,
see sample in my previous post
I used Ajax binding, but e.row is still undefined
0
Atanas Korchev
Telerik team
answered on 29 Sep 2010, 09:38 AM
Hello Rafael,

 Perhaps you are using the wrong event. You should use OnRowDataBound instead of OnDataBound.

I am locking this forum thread as it digressed from the original question.

Greetings,
Atanas Korchev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Jay
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Rafael
Top achievements
Rank 1
Diiimo
Top achievements
Rank 1
Share this question
or