2013-08-16 1 views
2

jQuery의 tablesorter과 결합하여 GridView의 스타일을 변경하여 행 색상을 교대로 지정할 수 있지만 각 열 그룹에 대한 색상 세트를 변경 할 수 있습니까?열 그룹 색상을 사용하여 행 색상을 교대로 추가 할 수 있습니까?

Example Image

나는 현재 내가 만든 배열에 따라 셀 배경 색상, 예를 하드 코딩 해요 : 아래 이미지 참조 greenArray는 (0,1,2,3)으로 설정된 정수 배열이고 purpleArray는 (4,5,6,7) 등입니다. 그러나 Tablesorter 플러그인을 사용하면 분명히 셀이 색상을 유지합니다. 교류 색상 :

enter image description here

편집 : 나는 현재 VB.NET에 배경 색상을 추가 해요. 다음 함수는 배열을 정의하고 실제로 스타일 적용 ColorizeMe() 함수를 호출 :

Private Sub StyleTable(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gvReport.RowDataBound 

      'Define arrays to color the gridview, if cell index is in array, it will be colored 
      Dim blueArray() As Integer = {0, 17, 18, 19, 20} 
      Dim greenArray() As Integer = {1, 2, 3, 4} 
      Dim purpleArray() As Integer = {5, 6, 7, 8} 
      Dim pinkArray() As Integer = {9, 10, 11, 12} 
      Dim yellowArray() As Integer = {13, 14, 15, 16} 

      _packworks.ColorizeMe(blueArray, greenArray, purpleArray, pinkArray, yellowArray, e.Row) 

End Sub 

그리고 ColorizeMe() 함수 : 당신의 행 이후

Public Sub ColorizeMe(ByVal blueArray() As Integer, ByVal greenArray() As Integer, _ 
           ByVal purpleArray() As Integer, ByVal pinkArray() As Integer, _ 
           ByVal yellowArray() As Integer, ByVal row As GridViewRow) 
      Dim i As Integer = 0 

      For Each cell As TableCell In row.Cells 
       If Array.IndexOf(blueArray, i) <> -1 Then 
        If _isDark Then 'Color account column 
         cell.BackColor = ColorTranslator.FromHtml("#B0C4DE") 
        Else 
         cell.BackColor = ColorTranslator.FromHtml("#E6E6FA") 
        End If 
       ElseIf Array.IndexOf(greenArray, i) <> -1 Then 
        If _isDark Then 
         cell.BackColor = ColorTranslator.FromHtml("#a4d5a8") 
        Else 
         cell.BackColor = ColorTranslator.FromHtml("#ddf5de") 
        End If 
       ElseIf Array.IndexOf(purpleArray, i) <> -1 Then 
        If _isDark Then 
         cell.BackColor = ColorTranslator.FromHtml("#ada4d4") 
        Else 
         cell.BackColor = ColorTranslator.FromHtml("#c7c6f4") 
        End If 
       ElseIf Array.IndexOf(pinkArray, i) <> -1 Then 
        If _isDark Then 
         cell.BackColor = ColorTranslator.FromHtml("#e3b3e0") 
        Else 
         cell.BackColor = ColorTranslator.FromHtml("#fae1fa") 
        End If 
       ElseIf Array.IndexOf(yellowArray, i) <> -1 Then 
        If _isDark Then 
         cell.BackColor = ColorTranslator.FromHtml("#e0e3ab") 
        Else 
         cell.BackColor = ColorTranslator.FromHtml("#f5f8dd") 
        End If 
       End If 

       i += 1 
      Next 

      _isDark = Not _isDark 
     End Sub 
+3

해당 코드를 피할 수 있습니까? 가능하지만 현재 작업하고있는 것을 더 쉽게 볼 수 있습니다. –

+0

나는 바이올린을 게시 할 수 있으면 좋겠다. 저는 현재 서버 측에서 .NET의 색상 배경을 추가하고 있습니다. 언어에 대한 지식이 거의없는 jQuery에서 동일한 기능을 수행 할 수 있는지 궁금했습니다. 그러나 내 생각에 대한 통찰력을 얻는 데 도움이된다면 설명에 서버 측 코드를 추가했습니다. 색상이 필요한 다양한 열이있는 여러 페이지가 있으므로 해당 배열이 최선의 선택이라고 생각했습니다. – TimeBomb006

답변

2

가 빛/어둠 번갈아됩니다, 당신은 알파 투명 배경 색상을 활용할 수 있습니다 :

http://cssdeck.com/labs/6rgab657

<table> 
    <colgroup class="a" span="4" /> 
    <colgroup class="b" span="4" /> 
    <colgroup class="c" span="4" /> 
    <colgroup class="d" span="4" /> 

    <tr> 
    <td>A</td> 
    <td>A</td> 
    <td>A</td> 
    <td>A</td> 
    <td>B</td> 
    <td>B</td> 
    <td>B</td> 
    <td>B</td> 
    <td>C</td> 
    <td>C</td> 
    <td>C</td> 
    <td>C</td> 
    <td>D</td> 
    <td>D</td> 
    <td>D</td> 
    <td>D</td> 
    </tr> 

    <tr> 
    <td>A</td> 
    <td>A</td> 
    <td>A</td> 
    <td>A</td> 
    <td>B</td> 
    <td>B</td> 
    <td>B</td> 
    <td>B</td> 
    <td>C</td> 
    <td>C</td> 
    <td>C</td> 
    <td>C</td> 
    <td>D</td> 
    <td>D</td> 
    <td>D</td> 
    <td>D</td> 
    </tr> 
</table> 

CSS :

.a { 
    background: blue; 
} 

.b { 
    background: green; 
} 

.c { 
    background: purple; 
} 

.d { 
    background: red; 
} 

tr:nth-child(odd) { 
    background: rgba(255, 255, 255, .70); 
} 
+0

이것을 구현하기 시작했습니다. 이것이 .NET이라는 것을 명심하십시오. 내 'TemplateFields' 각각에 대해'ItemStyle-CssClass' 속성을 추가하고 CSS 클래스를 파란색, 녹색 등으로 설정하여 잘 작동합니다. 그러나 CSS는'tr : nth-child (odd)'속성을 선택하지 않습니다. 나는 그것이'TemplateFields'에 설정 한 수동 클래스를 오버라이드 할 수 없는지 궁금합니다. – TimeBomb006

+1

색상이 어떻게 적용되는지에 따라 다릅니다. 'style = "background : red"'를 통해서라면 덮어 쓰기가 매우 어렵고 가능한 경우 제거하는 것이 가장 좋습니다. 클래스가있는 경우 선택기를 'tr : nth-child (odd) td'로 조정하여 더 구체적으로 지정할 수 있습니다. – cimmanon

관련 문제