简体   繁体   中英

How to set grid kendo fields condionnally?

I have a kendo grid with columns like below:

 columns: [
        {
          title: 'Solde Débiteur',
          field: 'sold', // if sold > 0
          filterable: { cell: { operator: 'eq', showOperators: false } }
        },
        {
          title: 'Solde Créditeur',
          field: 'sold', // if sold < 0
          filterable: { cell: { operator: 'eq', showOperators: false } }
        }
]

how can populate my grid anf set sold in first column if it is positive and in the second if negative?

thanks in advance.

You can use template to fill column conditionally. For example:

 columns: [
        {
          title: 'Solde Débiteur',
          field: 'sold', // if sold > 0
          filterable: { cell: { operator: 'eq', showOperators: false } },
          template: "<div>#= sold > 0 ? sold :0 #</div>" //if sold > 0 return sold else 0
        },
        {
          title: 'Solde Créditeur',
          field: 'sold', // if sold < 0
          filterable: { cell: { operator: 'eq', showOperators: false } }
          template: "<div>#= sold < 0 ? sold :0 #</div>" // if sold < 0 return sold else 0
        }
]

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