gpt4 book ai didi

jquery - 添加交替的行颜色和列分组颜色——这可能吗?

转载 作者:行者123 更新时间:2023-11-28 11:40:29 26 4
gpt4 key购买 nike

是否可以设置 GridView 的样式(结合 jQuery 的 tablesorter)以具有交替的行颜色,但更改每个列分组的颜色集?见下图:

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

最佳答案

由于您的行是交替的亮/暗,您可以利用 alpha 透明背景颜色:

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

关于jquery - 添加交替的行颜色和列分组颜色——这可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18280703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com