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

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

问题描述:

我在$(document).ready(

I use the following line at the $(document).ready(

$("#stSearchTermsGrid").setCell(2, 2, '', {color:'red'}) ;

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

but it doesn't work. Did I write it in a wrong way or placed it in the wrong place.

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

I know this question has been asked more than once before and this is how I got the first line. But I am still not able to do it and not knowing where the problem is.

您是对的,您不是第一个提出问题的人.为了清除单元格颜色的情况,我做了演示

You are right you are not the first person who ask the question. To clear the situation with the cell color I made the demo

适合您,您可以通过不同的方式更改单元格的文本颜色或卖方的背景颜色:

for you which change the text color of the cell or the background color of the sell in different ways:

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');
}

其中

<style type="text/css">
    .my-highlight { color: red; }
</style>

和"3","4","6","8","10"和"12"是将更改相应列的颜色的行的rowid.

and "3", "4", "6", "8", "10" and "12" are th rowid of the rows where the color of the corresponding column will be changed.

顺便说一句,我个人最喜欢的方法是使用类的ui-state-highlight或ui-state-error ui-state-error-text类. /jqueryui.com/docs/Theming/API"rel =" noreferrer> jQuery UI主题.

By the way my personal favorites are the ways using 'ui-state-highlight' or 'ui-state-error ui-state-error-text' classes which are the part of the jQuery UI Themes.

更新:为了了解在使用另一个jQuery UI主题的情况下不同方法的用法的区别,我添加了

UPDATED: To understand the difference of the usage of different methods in case of the usage of another jQuery UI Theme I added one more demo used La Frog Theme where the same table as above look like the following: