jqGrid具有自定义单元格颜色

Anu*_*yal 6 grid jquery jqgrid

是否有可能在jqGrid(jquery网格http://www.trirand.com/blog/)中有自定义单元格文本颜色,例如在价格列中我想要红色,如果价格> 100 $,绿色如果价格<50 $其他灰色?

更普遍的做法

  1. jqGrid提供了更改网格单元视图的钩子,例如,我可以在创建或修改price列的单元格时注册回调.

  2. 或者是否可以有单独的模型和视图(客户端),例如从服务器我可以为每一行发送两个数据,即如何显示和显示什么

编辑:所以这里是一个示例显示样本格式化程序,它根据值为单元格着色

function infractionInFormatter(el, cellval, opts)
{
    $(el).html(cellval).css('color',infraction_color_map[cellval]);
}

colModel :[ 
    ...
    {name:'date', index:'date', width:120, date:true}, 
    {name:'inf_out', index:'inf_out', width:60, formatter:infractionInFormatter,},
    ...
],
Run Code Online (Sandbox Code Playgroud)

Cra*_*ntz 8

是的,你可以这样做.编写自定义格式化程序.这只是一个在colModel中传递引用的函数.您可以在函数中获得对最终单元格选择器的引用,因此您可以在格式化程序中使用jQuery执行任何操作.包括改变颜色/款式.