2009-04-20 119 views
6

是否有可能在jqGrid(jQuery網格http://www.trirand.com/blog/)具有自定義單元格文字顏色,例如在價格欄中,如果價格> 100 $,則需要​​紅色,如果價格爲綠色,則需要綠色< 50 $其他灰色?jqGrid與自定義單元格顏色

更一般做

  1. 的jqGrid提供了鉤子改變網格cellview,例如當價格欄的單元格被創建或修改時,我可以註冊回調。

  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,}, 
    ... 
], 

回答

8

是的,你可以做到這一點。寫一個custom formatter。這只是您在colModel中傳遞引用的函數。你得到了函數中最後的單元格選擇器的引用,所以你可以用一個格式化程序完成jQuery的任何工作。包括改變顏色/樣式。

-1

如果單元格有xxx值,我會設置一個紅色背景顏色,如果值是yyy,我會設置一個綠色背景。

我已經寫了這個代碼:

..... 
colModel:[ 
    {name:'id',index:'id', width:15,hidden:true, align:"center"}, 
    {name:'title',index:'title', width:150, align:"center"}, 
    {name:'start',index:'start', width:350, align:"center", sorttype:"date"}, 
    {name:'fine',index:'fine', width:350, align:"center", sorttype:"date"}, 
    {name:'completed',index:'completed', width:120, align:"center",formatter:infractionInFormatter},   
    ], 
..... 

而且這個功能就像你的例子:

function infractionInFormatter(el, cellval, opts) 
     { 
      ..... 
     } 

我怎麼也得設置呢?

非常感謝。

+1

這不是一個答案的。去[這裏](http://stackoverflow.com/questions/ask)如果你想問一個問題。 – FastTrack 2012-11-20 14:31:30

2

您還可以指定在colModel類:

colModel: [ 
      { 
      name:'field_x', 
      index:'field_x', 
      align: 'left', 
      width: 35, 
      classes: 'cvteste' 
      }, 
      ..... 
      ] 
相關問題