2009-04-20 4 views
6

jqGrid (jquery grid http://www.trirand.com/blog/)에서 사용자 정의 셀 텍스트 색상을 사용할 수 있습니까? 가격 열에 나는 가격이 100 $보다 높으면 녹색을 원하고 가격이 녹색이면 가격은 <입니다.사용자 정의 셀 색상의 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

이 전혀 응답하지 않습니다. 질문을 원하면 [here] (http://stackoverflow.com/questions/ask)로 이동하십시오. – FastTrack

2

또한 colModel의 클래스를 지정할 수 있습니다

colModel: [ 
      { 
      name:'field_x', 
      index:'field_x', 
      align: 'left', 
      width: 35, 
      classes: 'cvteste' 
      }, 
      ..... 
      ] 
관련 문제