web-dev-qa-db-ja.com

jqGridセルの色を変更するには?

$(document).ready(で次の行を使用します

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

しかし、それは機能しません。私はそれを間違った方法で書いたか、間違った場所に置きましたか?.

私はこの質問が以前に何度も尋ねられたことを知っています、そしてこれは私が最初の行を得た方法です。しかし、私はまだそれを行うことができず、問題がどこにあるのかわかりません。

17
Ahmad Farid

あなたは正しいですあなたは質問をする最初の人ではありません私が作ったセルの色で状況をクリアするために デモ

enter image description here

セルのテキスト色またはセルの背景色をさまざまな方法で変更する場合:

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」は、対応する列の色が変更される行の行IDです。

ちなみに、私の個人的なお気に入りは、 jQuery UI Themes の一部である「ui-state-highlight」または「ui-state-error ui-state-error-text」クラスを使用する方法です。

[〜#〜] updated [〜#〜]:別のjQuery UIテーマを使用する場合の、異なるメソッドの使用の違いを理解する私は追加しました 1つ以上のデモ 上記と同じテーブルが次のようになるLa Frog Themeを使用しました:

enter image description here

47
Oleg