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

Get current row data with custom command

1 Answer 4925 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 31 May 2012, 12:23 AM
I need to get the row data (firstname, lastname) from the current row from a custom command.  I need to create a vcard from the custom command and the first name, last name will be used in the back end to dynamically generate the vcard but I have been trying to extract the current row data and have so far been unsuccessful.  Here's my code....
$(function() {
    var grid = $("#grid").kendoGrid({
        dataSource : {
            pageSize:10,
            sort : {
                field : "firstname",
                dir : "asc"
            },
            transport : {
                read : "data/getemployees.php"
            },
            schema : {
                data : "data",
                total: "data.length"
            },
        },
        pageable: true,
        columns : [{
            field : "firstname",
            title : "First Name"
        }, {
            field : "lastname",
            title : "Last Name"
        }, {
            field : "cellphone",
            title : "Cell Phone"
        }, {
            field : "deskphone",
            title : "Desk Phone"
        }, {
            field : "emailaddress",
            title : "Email Address"
        },{
            command:{text:"vCard", className:"vCardButton"}, title:"vCard", width:"110px"
        }],
        sortable:true,
    });
       $("#grid").delegate(".vCardButton", "click", function(e) {
                       
                        var grid = $("#grid").data("kendoGrid");
                       
                        var myVar = grid.dataItem(grid.tbody.find(">tr"));
                       
                    });
});

any suggestions?

1 Answer, 1 is accepted

Sort by
1
Alexander Valchev
Telerik team
answered on 31 May 2012, 12:24 PM
Hello Adam,

The problem is with the jQuery selector that you are using to select the dataItem. Please test your code with the following change:
//get current dataItem
var myVar = grid.dataItem($(this).closest("tr"));

I would also recommend to take a look at the custom command as it demonstrates a case similar to yours.

All the best,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or