CONDITIONALLY FORMAT KENDO GRID COLUMN | URDINESH

Software Programming, Tutorials, Interview Preparations,Stock Market,BSE/NSE, General informations

Saturday, August 16, 2014

CONDITIONALLY FORMAT KENDO GRID COLUMN

Hi All,

Many of us struck with conditionally formatting Kendo Grid Columns. Here is the solution,


There are two ways you can do this,
  1. Using Template Function
  2. Using Client Template Function

You can use template function when there is no requirement for sorting of that column in the kendo grid.

So I always suggest Client template property of kendo grid .

 Use the following way to do this,
                                    .ClientTemplate(
                                   "# if (DataField == null) { #" +
                                   " " +
                                   "# } else if (DataField == 0) { #" +
                                   " " +
                                   "# } else { #" +
                                   "<div>#= kendo.toString(DataField , '<FormatString>') #&nbsp;</div>" +
                                   "# } #"

                                   );
Example:
                                   .ClientTemplate(
                                   "# if (empSalary == null) { #" +
                                   "&nbsp;" +
                                   "# } else if (empSalary == 0) { #" +
                                   "&nbsp;" +
                                   "# } else { #" +
                                   "<div>#= kendo.toString(empSalary , 'c') #&nbsp;</div>" +
                                   "# } #"
                                   );
Note:

Here I am giving Data field preceding its object name. 

No comments:

Post a Comment

Thanks for your valuable comments

Followers