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

Change grid column template with button click

2 Answers 13 Views
Application
This is a migrated thread and some comments may be shown as answers.
Umutcan
Top achievements
Rank 1
Iron
Umutcan asked on 04 Mar 2021, 12:44 PM

Hi,

I have a kendo toolbar with multiple dropdowns and checkboxes to filter my datasource. What I want is when I submit my filter selections, if a spesific checkbox is checked, then datetime column of the grid will have this template:

"#= kendo.toString(kendo.parseDate(dates), 'dd/MM/yyyy') #"

If the checkbox not checked (or the page is just loaded with empty checkbox in default scenario) the column will have:

"#= kendo.toString(kendo.parseDate(dates), 'dd/MM/yyyy HH:mm') #"

as template. 

I tried conditioning inside of grid but I didn't manage to obtain checkbox value. I tried writing a function outside the grid function but when I refresh grid data with:

var grid = $("#grid").data("kendoGrid");
grid.dataSource.data(reportData);

it only refresh the data inside grid, that does not trigger the template function.

How can I change the column template while refreshing the data according to that checkboxs value? 

 

Greets Umutcan

2 Answers, 1 is accepted

Sort by
0
Umutcan
Top achievements
Rank 1
Iron
answered on 04 Mar 2021, 03:56 PM

Managed to do that with following code:

template: function (dataItem) {
    var dateOriginal = new Date(dataItem.dates).toLocaleString();
    if ($("#isDaily").is(':checked')) {
        var dateStr = dateOriginal.split(" ");
        return dateStr[0];
    }
    return dateOriginal.substring(0, dateOriginal.length - 3);
}

 

0
Nikolay
Telerik team
answered on 09 Mar 2021, 12:20 PM

Hi Umutcan,

Thank you for sharing the solution you came up with. This is a valid approach to the requirement and I believe others facing the same scenario will benefit from it.

Let us know if anything new arises.

Regards,
Nikolay
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Application
Asked by
Umutcan
Top achievements
Rank 1
Iron
Answers by
Umutcan
Top achievements
Rank 1
Iron
Nikolay
Telerik team
Share this question
or