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

Checkbox Column problem

1 Answer 321 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Goran
Top achievements
Rank 1
Goran asked on 16 Oct 2014, 08:35 AM
Hello, I'm having trouble setting up checkbox column in my grid. I am using inline edit mode and my checkbox column is se up like this

@(Html.Kendo().Grid<URBIS.ViewModels.PropisiViewModel>()
.Name("grid")
.Events(e => e.DataBound("onDataBound"))
.Columns(columns =>
{
 
    columns.Bound(p => p.GrupePropisa).ClientTemplate("#=GrupePropisa.Naziv#").EditorTemplateName("GrupePropisa").Width(220);
    columns.Bound(p => p.Naziv).Width(220);
    columns.Bound(p => p.SluzbeniList).Width(220);
    //columns.Bound(p => p.Aktivan).Width(120);
    columns.Bound(p => p.Aktivan)
              .Title("Aktivan")
              .ClientTemplate("<input type='checkbox' #= Aktivan ? checked='checked': '' # class='chkbx' />")
              .HtmlAttributes(new {style = "text-align: center"})
              .Width(50);
})

and script handling check events is
$(function () {
    $('#grid').on('click', '.chkbx', function () {
        var checked = $(this).is(':checked');
        var grid = $('#grid').data().kendoGrid;
        var dataItem = grid.dataItem($(this).closest('tr'));
        dataItem.set('Aktivan', checked);
    });
});

The problem I'm experiencing is very weird. Binding to bool field from database works fine, editing also but when inserting, checkbox always passes as false. Very weird. Also, I would like the checkbox to be disabled if the row is in read only mode and to be editable if the row is in edit/insert mode. Any help? Lost few hours on this and this is too much :)

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 20 Oct 2014, 07:40 AM
Hello Goran,

In that case I would suggest removing the "click" event handler and let the default editor template deal with the value of the checkbox. Also, adding a "disabled" attribute to the input element in the client template should help. For example: 
columns.Bound(p => p.Aktivan)
              .Title("Aktivan")
              .ClientTemplate("<input type='checkbox' #= Aktivan ? checked='checked': '' # disabled='true' />")
              .HtmlAttributes(new {style = "text-align: center"})
              .Width(50);

I am not exactly sure what is causing the new items to be sent with false though. Could you please examine the Create request in the browser's network tab and check if the correct values are sent to the server? This would help us identify if the issue is client or server-side.

Regards,
Alexander Popov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Goran
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or