简体   繁体   中英

How to add conditional column for kendo ui grid using angular js?

How can we add a conditional column to the kendo ui grid .

I am having JSON input like this

    [{
    "ProductID": 1,
    "ProductName": "Chai",
    "Supplier": {
        "SupplierID": 1,
        "SupplierName": "Exotic Liquids"
    },
    "Category": {
        "CategoryID": 1,
        "CategoryName": "Beverages"
    },
    "UnitPrice": 18.0,
    "UnitsInStock": 39,
    "Discontinued": false,
    "layers": [
      {
         "layer_Layer1": {
            "layerType": "top",
            "layer": "L1",
            "groups": []
         }
      }  ]
},{
    "ProductID": 2,
    "ProductName": "Chang",
    "Supplier": {
        "SupplierID": 1,
        "SupplierName": "Exotic Liquids"
    },
    "Category": {
        "CategoryID": 1,
        "CategoryName": "Beverages"
    },
    "UnitPrice": 19.0,
    "UnitsInStock": 17,
    "Discontinued": false,
    "layers": [
      {
         "layer_Layer2": {
            "layerType": "top",
            "layer": "L2",
            "groups": []
         }
      }
   ]
}]

Here in columns.fields I am giving layers[0].layer_Layer1.layer but sometimes I get layers[0].layer_Layer2.layer .

How can we configure this in kendo ui ?

Plunker : here

If I get you right you want to display in a column the value of either layer_Layer1 or layer_Layer2 , depending on which one is blank or not.

You can try a template for that:

# if (layers && layers[0].layer_Layer1) { # 
    #: layers[0].layer_Layer1.layer # 
# } else if (layers && layers[0].layer_Layer2) { #
    #: layers[0].layer_Layer2.layer # 
# } #

Updated demo. Another version .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM