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?
You can use Javascripts inline if format
#= street2 != null ? street2 : '' #
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> # } #
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With