x-extends / vxe-table

Vxe table 的表格组件
https://vxetable.cn
MIT License
7.61k stars 1.05k forks source link

v-if vxe-grid cellRender 返回class不生效,想根据值的范围改变颜色(cellRender that returns a html tag is not working) #871

Closed marissagroves closed 4 years ago

marissagroves commented 4 years ago

(必填)请填写问题描述 Describe

v-if 中vxe-grid cellRender 返回class不生效,想根据值的范围改变颜色。 同样的配置,在vxe-table里面是生效的, 改成vxe-table就不生效了。 Need help in finding the correct config in vxe-grid. Can anyone help me?

(必填)请填写能重现问题的链接,例如(jsfiddlecodesandboxjsrun) Reproduction link

VXETable.renderer.add('allocatedRate', { // 默认显示模板 renderDefault(h, renderOpts, params) { const { row, column } = params; const { service, decimals } = renderOpts.props; if (row[column.property] >= whiteList[service].RES_RATE) { return [ <span class="up">{percent(row[column.property], decimals)}</span> ]; } else { return [ <span class="down">{percent(row[column.property], decimals)}</span> ]; } } }); ... { field: 'allocatedRate', title: '分配率', sortable: true, filters: [{ data: { type: 'has', isCase: true, name: '' } }], filterRender: { name: 'FilterComplex' }, cellRender: { name: 'allocatedRate', props: { service: 'ECS', decimals: 2 } } } ... .up { color: green; font-weight: bold; } .down { color: red; font-weight: bold; }

请填写报错信息或截图 Error message or screenshots

1.Vxe grid config: image

  1. Add allocatedRate in renderer: image
  2. Config in the table columns: image
  3. CSS: .up { color: green; font-weight: bold; } .down { color: red; font-weight: bold; } 5: Expected result: image
  4. Actual effect: image

(必填)请填写版本号 Version

marissagroves commented 4 years ago

I changed the return JSX style to the following: VXETable.renderer.add('allocatedRate', { // 默认显示模板 renderDefault(h, renderOpts, params) { const { row, column } = params; const { service, decimals } = renderOpts.props; if (row[column.property] >= whiteList[service].RES_RATE) { return [ <span style={{ color: 'green', 'font-weight': 'bold' }}> {percent(row[column.property], decimals)} </span> ]; } else { return [ <span style={{ color: 'red', 'font-weight': 'bold' }}> {percent(row[column.property], decimals)} </span> ]; } } }); And then it was solved...