How do you conditionally style a cell in a Dojo data grid?

∥☆過路亽.° 提交于 2019-12-07 06:04:07

问题


Essentially what I want to do is to apply additional CSS classes to individual cells in a data grid based on the value of the cell. An example would be to color the text red when a dollar value is negative.

The only solution I've found was to use the formatter of the column to create a string for a span that has the class based on the value passed in. I figure there has to be a better way.


回答1:


When specifying the structure, you pass in an object that represents the widget configuration for a given column. As part of this object, include a formatter function in the definition:

{
...
 formatter: function(val, rowIdx, cell) {
    classes = compute_classes(val, rowIdx, cell);
    cell.customClasses.push(classes);
  }
}

however your 'compute_classes' computes the classes to use is up to you. They will be applied to the cell, and then you can manage their appearance in your CSS.



来源:https://stackoverflow.com/questions/2553734/how-do-you-conditionally-style-a-cell-in-a-dojo-data-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!