Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check null values using kendo template

Tags:

Hi I've a kendo grid like below and I wanted to check null value for column and based on condition I want to display some default number to the column

Here is my sample code.

 $("#eCount").kendoGrid({         dataSource: {             data: myModel,             pageSize: 5 },        columns: [             {                 field: "Count",                 title: "Count",                 template: '# if (Count == "null" ) {#1#} else {#Count#}#'             }] }); 

But I'm not getting how to get it done. Any solution?

like image 425
jestges Avatar asked Aug 05 '13 17:08

jestges


2 Answers

You can use Javascripts inline if format

#= street2 != null ? street2 : '' # 
like image 94
vordimous Avatar answered Sep 16 '22 18:09

vordimous


I found this to be the most usefull:

#= typeof street2 == "undefined" || street2 == null ? "" : street2 # 

The typeof check can be useful when adding rows programatically to the grid's datasource and not specifying the value for the street2 field:

grid.dataSource.add({}); //this line will generate an error when you're not using 'typeof' check 

Also related to your question, for more complex scenarios, I've also found useful to do other checks inside the template using data.xxx, like this:

# if (data.street2 && data.street2.length) { #     <span>#: street2 # </span> # } else { #     <span>N/A</span> # } # 
like image 43
Lucian Avatar answered Sep 20 '22 18:09

Lucian