Kendo UI grid rowTemplate - calling a function to affect the css of td cells

后端 未结 2 1179
温柔的废话
温柔的废话 2021-01-26 06:54

My Kendo UI grid is dynamic, where the columns can be defined as field0, field1 through field[n] ; I do NOT know the number

2条回答
  •  没有蜡笔的小新
    2021-01-26 07:20

    I think it will be hard to sync the columns with the column headers if you use a row template. What I'd do is use a dynamically created client template and place the business logic inside that one instead.

     function getTemplate(field, fieldName){
    
        var color;
    
        if(field[fieldName] > 4000000){
          color = "green";
        }else{
          color = "red";
        }
    
        return "" + field[fieldName] + "";
      }
    
      vm.userGridOptions = {
                selectable: true,
                sortable: true,
                pageable: true,       
                columns: [
                  { field: "field0" },
                  { field: "field1", 
                    template: (function(dataItem){
    
                       return getTemplate(dataItem, "field1");
                      }) 
                  },
    

    Example:

    http://plnkr.co/edit/lPUzfu?p=preview

提交回复
热议问题