如何改变jqGrid单元格的颜色?

Ahm*_*rid 17 jquery-ui jqgrid

我在$(document).ready上使用以下行(

$("#stSearchTermsGrid").setCell(2, 2, '', {color:'red'}) ;
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我是以错误的方式写它还是把它放在错误的地方.

我知道这个问题不止一次被问过,这就是我得到第一行的方式.但我仍然无法做到这一点,也不知道问题出在哪里.

Ole*_*leg 47

你是对的,你不是第一个提出这个问题的人.为了清除细胞颜色的情况我做了演示

在此输入图像描述

对于您以不同方式更改单元格的文本颜色或销售的背景颜色:

loadComplete: function() {
    // 2 is zero-base index of the column 'name' ('Client'). Every from the options
    // multiselect:true, rownumbers:true and subGrid:true will increase
    // the index by 1 because the option inserts additional columns
    $("#6 td:eq(2)", grid[0]).css({color:'red'});

    grid.jqGrid('setCell',"12","name","",{color:'red'});
    grid.jqGrid('setCell',"10",'name', '', 'my-highlight');
    grid.jqGrid('setCell',"8",'name', '', 'ui-state-error ui-state-error-text');

    grid.jqGrid('setCell',"4","name","",{'background-color':'yellow',
                                         'background-image':'none'});
    grid.jqGrid('setCell',"3","name","",'ui-state-highlight');
}
Run Code Online (Sandbox Code Playgroud)

哪里

<style type="text/css">
    .my-highlight { color: red; }
</style>
Run Code Online (Sandbox Code Playgroud)

"3","4","6","8","10"和"12"是行的第二行,其中相应列的颜色将被改变.

顺便说一句,我个人最喜欢的方式是使用'ui-state-highlight'或'ui-state-error ui-state-error-text'类,它们是jQuery UI主题的一部分.

更新:为了理解在使用另一个jQuery UI主题的情况下不同方法的使用差异,我添加了一个使用La Frog Theme的演示,其中上面的相同表格如下所示:

在此输入图像描述

  • 你给出的好答案! (2认同)