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

Get Value of Checkbox in column

1 Answer 1835 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 02 May 2013, 08:00 PM
Can someone please provide me with a few lines of code to get the value of a checkbox in a column in a Kendo Grid. Starting with this code:

columns.Bound(o => o.Resolved).ClientTemplate("&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' # if (Resolved) { #checked='checked'# } #/>").Title("Resolved").Width(60).Sortable(false);
                  
var data = $("#Appointments").data("kendoGrid").dataSource.data();

$.each(data, function (index, item)
{ trArray = { "Resolved": item.Resolved    <<--- This gives me the value IN THE MODEL --- I WANT WHAT THE USER HAS SELECTED!       }; });

Please don't send me a solution that hangs Visual Studio for an answer.

Thanks,
Rajendra
Top achievements
Rank 1
commented on 02 Nov 2021, 08:24 AM

Hi All, 

I have the similar query, I have a kendo grid with Checkbox(Templete) and ID, On click of delete all button i want the id of the record which is checked, Could you please help me on this?

Nikolay
Telerik team
commented on 04 Nov 2021, 08:22 AM

Hi Rajendra,

This is demonstrated in the following article:

Namely:

{ template: '#=dirtyField(data,"Discontinued")#<input type="checkbox" #= Discontinued ? \'checked="checked"\' : "" # class="chkbx k-checkbox" />', width: 110 },
...
$("#grid .k-grid-content").on("change", "input.chkbx", function(e) {
        var grid = $("#grid").data("kendoGrid"),
            dataItem = grid.dataItem($(e.target).closest("tr"));
        console.log(dataItem.id)

        dataItem.set("Discontinued", this.checked);
      })

I hope this helps.

Regards,

Nikolay

1 Answer, 1 is accepted

Sort by
0
Eric
Top achievements
Rank 1
answered on 03 May 2013, 03:01 PM
Never mind.


columns.Bound(o => o.Resolved).ClientTemplate("&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' class='resolved' # if (Resolved) { #checked='checked'# } #/>").Title("Resolved").Width(60).Sortable(false);
columns.Bound(o => o.IHAAppointmentID).Hidden(true).HtmlAttributes(new { id = "ID" });

$(".k-grid-content tbody tr").each(function ()
        {
            var $row = $(this);
            var checked = $row.find('.resolved').attr('checked');
            var id = $row.find('#ID').text();

            trArray = { 
            
                        "AppointmentID": id,
                        "Resolved": checked === "checked" ? true : false
            };

            jsonArray.push(trArray);

        });
Tags
Grid
Asked by
Eric
Top achievements
Rank 1
Answers by
Eric
Top achievements
Rank 1
Share this question
or