Search code examples
javascriptjqueryif-statementkendo-uikendo-grid

KendoUI grid if field is true/false change title


I have a boolean isActive that returns TRUE or FALSE

           {
                field: "isActive",
                title: "Status",
                width: 90

            }

I've managed to make this work and in the grid it will show 'true' or 'false'. However I want to make it if its true, change field to A and if false change title to B. How can I do this?

EDIT: This is how they are written usually (field,title, width, template etc). IsActive is a boolean, and I want it to perform a check (if isActive = true, return A. Not sure how to explain it. Currently it its displaying the boolean value (true/false) and I want it to display Active/Inactive in the grid. Sorry for the confusion, the title will remained unchanged


Solution

  • You can use a column template function (http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.template):

    { field: "isActive",
      template: function(dataItem){
          return dataItem.isActive ? "Active" : "Inactive";
      }
    }
    

    DEMO