Christofer Ohlsson
Christofer Ohlsson

Reputation: 3145

On client side get value of first cell in RadGrid row upon row creation

My grid has an OnRowCreated event as such:

function grdBookingItems_rowCreated(sender, eventArgs) {
               console.log(eventArgs.get_gridDataItem().get_element());
            }

But obviously this isn't what it's supposed to look like in the end. What I want to do is to create a click event for the last on the row, whose argument is created from the text found in the first element.

Every row looks sort of like this:

<tr>
    <td>44</td>
    <td>foo</td>
    <td>bar</td>
    <td><div class="button"></div></td>
</tr>

And so I want to do something like storing the tr in a Jquery variable and then using its children. But how do I retrieve the tr?

The data I log to the console above looks like this:

<tr id="grdFoo_ctl00__0" class="rgRow">

But I haven't found from the Telerik RadGrid API how I am to retrieve a reference to the tr.

Upvotes: 1

Views: 1661

Answers (3)

Jayesh Goyani
Jayesh Goyani

Reputation: 11154

Please try with the below code snippet.

    function RowCreated(sender, args) {
        var $trJaueryVariable = $(args.get_gridDataItem().get_element());
        //Access your tr in a Jquery variable 
    }

I have already applied above code in this code and it works for me.

Let me know if any concern.

Upvotes: 0

rdmptn
rdmptn

Reputation: 5603

Have you given the event arguments a chance? THe dataKeyValues collection can help: http://www.telerik.com/help/aspnet-ajax/grid-onrowcreated.html. Note that you would need to add the needed fields to the ClientDataKeyNames collection of the MasterTableView http://www.telerik.com/help/aspnet-ajax/grid-extract-key-values-client-side.html

Upvotes: 0

Christofer Ohlsson
Christofer Ohlsson

Reputation: 3145

Okay, I guess I solved it. Not sure if it's the prettiest way of doing things, but it works:

function grdBookingItems_rowCreated(sender, eventArgs) {
                var rowId = eventArgs.get_gridDataItem().get_element().id;
                var row = $("#" + rowId);
                var firstId = row.children().first().html();
            }

Upvotes: 1

Related Questions