Rob
Rob

Reputation: 225

How can i get Selected Kendo Grid cell Value

I have the following code to display the selected KendoGrid Row in a form. I used this code it looks like it will take me to what i want to accomplish but I need help instead of displaying only the first cell, i also want to display the rest of values and display in the form as $("#ID").val(value);

which only displays the first <td> text but i want to

      $("#AddressGrid").on("click", "td", function (e) {
        var row = $(this).closest("tr");
        var ID= row.find("td:first").text();
          $("#ID").val(ID);// this display the selected row first cell in #ID text form but i want to access the rest of cell
        console.log(ID);
});

Upvotes: 0

Views: 2967

Answers (1)

rabink
rabink

Reputation: 759

First of all, the line row.find("td:first") selects only first td of the row. So, you should use row.find("td") instead and iterate through all the results to access each cell of the grid. E.g.

$("#AddressGrid").on("click", "td", function (e) {
    var row = $(this).closest("tr");
    var textVal = "";
    row.find("td").each(function(i, r) {
        textVal += `Col ${i+1}: ${r.innerText}\n`;
    });
    alert(textVal);
});

Upvotes: 2

Related Questions