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

InCell Editing a checkbox

1 Answer 217 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Iron
Veteran
Iron
Ed asked on 02 Apr 2020, 07:02 AM

Hi,

I have:

columns.Bound(t => t.IsActive).Width(45)

 

.ClientTemplate("#=dirtyField(data,'IsActive')# <input type='checkbox' #=IsActive ? checked='checked':'' # ;/>")

.HtmlAttributes(new { style = "text-align:center; " });

 with the following javascript which, I believe I got from Telerik

function dirtyField(data, fieldName)
{
    var hasClass = $("[data-uid=" + data.uid + "]").find(".k-dirty-cell").length < 1;
    if (data.dirty && data.dirtyFields[fieldName] && hasClass)
        return "<span class='k-dirty'></span>";
    else
        return "";
}

 

It works great if I click on the cell first and then check/uncheck the checkbox.

However, if I click directly on the checkbox it doesn't flag it as dirty and the changes are not saved.

Can someone point me in the right direction?

Thanks … Ed

 

 

 

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 06 Apr 2020, 01:18 PM

Hello Ed,

 

Out of the box the ClientTemplate can be used to customize the way data is presented, it was not designed to edit the underlying data. This is why modifying the checkbox in the ClientTemplate does not change the field of the value. When the cell is clicked first the Grid will place it in edit mode and will show an editor that can alter the value of the relevant field.

 

With that said, I would recommend making the checkbox in the ClientTemplate disabled so the users are not confused that it can be used for editing. When the cell is clicked the actual checkbox editor will be shown and can be used to alter the value.

 

.ClientTemplate("#=dirtyField(data,'IsActive')# <input type='checkbox' #=IsActive ? checked='checked':'' # ; disabled='disabled'/>")

 

Another option is to use the checkbox in the ClientTemplate as an editor. That will require preventing the default editing mechanism and handling the operation manually. Like illustrated in the following example

https://docs.telerik.com/kendo-ui/knowledge-base/grid-bound-checkbox-editable-column

 

The sample uses the KendoUI for jQuery Grid, however, the same logic is applicable for the .NET Core wrappers as well.

 

Regards,
Viktor Tachev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Ed
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Viktor Tachev
Telerik team
Share this question
or