希望有人可以帮助我,因为我还在了解DataTables.net
我有以下使用DataTables.net库启动的html表。日期列是动态生成的服务器端,所以我永远不知道会有多少列。
描述必须保持原样,但我想移动描述列旁边的整个总计列。我还想要一个选项,如果可能的话,用一个按钮隐藏所有日期列。
我真的希望有人能指出我正确的方向。请问是否有任何不清楚的地方。提前谢谢。
<table>
<thead>
<tr>
<th>Description</th>
<th>1-Nov-2017</th>
<th>2-Nov-2017</th>
<th>3-Nov-2017</th>
<th>4-Nov-2017</th>
<th>5-Nov-2017</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>[13] ADDED-3-Nov-2016</td>
<td>13 463.30</td>
<td>11 351.90</td>
<td>29 513.00</td>
<td>13 642.50</td>
<td>0.00</td>
<td>67 970.70</td>
</tr>
<tr>
<td>[16] ADDED-16-Feb-2017</td>
<td>10 791.60</td>
<td>3 237.80</td>
<td>14 054.80</td>
<td>15 547.90</td>
<td>0.00</td>
<td>43 632.10</td>
</tr>
<tr>
<td>[17] ADDED-18-Jul-2016</td>
<td>20 021.60</td>
<td>14 083.30</td>
<td>23 634.40</td>
<td>19 115.50</td>
<td>10 230.20</td>
<td>87 085.00</td>
</tr>
<tr>
<td>[2] AAPSTERT</td>
<td>20 544.40</td>
<td>14 900.00</td>
<td>23 156.30</td>
<td>13 131.40</td>
<td>0.00</td>
<td>71 732.10</td>
</tr>
<tr>
<td>[3] JANA</td>
<td>11 883.30</td>
<td>14 948.10</td>
<td>12 525.10</td>
<td>15 934.10</td>
<td>6 824.20</td>
<td>62 114.80</td>
</tr>
<tr>
<td>[31] ADDED-8-Apr-2016</td>
<td>32 813.50</td>
<td>36 833.40</td>
<td>33 099.10</td>
<td>17 500.70</td>
<td>4 295.00</td>
<td>124 541.70</td>
</tr>
<tr>
<td>[51] ADDED-16-Feb-2017</td>
<td>6 235.10</td>
<td>8 213.40</td>
<td>14 132.40</td>
<td>8 996.70</td>
<td>6 105.30</td>
<td>43 682.90</td>
</tr>
<tr>
<td>[52] ADDED-16-Feb-2017</td>
<td>5 425.30</td>
<td>5 422.80</td>
<td>7 295.80</td>
<td>6 439.40</td>
<td>6 458.80</td>
<td>31 042.10</td>
</tr>
<tr>
<td>[6] ADDED-28-Jul-2016</td>
<td>10 088.90</td>
<td>15 562.90</td>
<td>17 760.70</td>
<td>11 091.20</td>
<td>0.00</td>
<td>54 503.70</td>
</tr>
<tr>
<td>[61] ADDED-16-Feb-2017</td>
<td>8 346.80</td>
<td>5 448.00</td>
<td>16 083.60</td>
<td>14 548.20</td>
<td>16 670.60</td>
<td>61 097.20</td>
</tr>
<tr>
<td>[71] ADDED-28-Aug-2017</td>
<td>18 956.10</td>
<td>11 652.70</td>
<td>24 738.00</td>
<td>11 238.70</td>
<td>7 665.90</td>
<td>74 251.40</td>
</tr>
<tr>
<td>[72] ADDED-8-Apr-2016</td>
<td>12 277.10</td>
<td>8 489.90</td>
<td>13 718.10</td>
<td>9 860.70</td>
<td>9 619.10</td>
<td>53 964.90</td>
</tr>
</tbody>
<tfoot>
<tr class="totals">
<td>Totals:</td>
<td>170 847.00</td>
<td>150 144.20</td>
<td>229 711.30</td>
<td>157 047.00</td>
<td>67 869.10</td>
<td>775 618.60</td>
</tr>
</tfoot>
</table>
下面是经典的ASP服务器端代码,如果有人可以帮助解决这个问题。
<table id="scrollTable" class="table table-striped table-bordered table-condensed" style="width:100%">
<thead>
<tr>
<th class="all">Description</th>
<%if isArray(vntData) then%>
<%for intX = 0 to DateDiff("d", StartDate, EndDate)%>
<th><%=fmtDate(DateAdd("d", intX, StartDate))%></th>
<%next%>
<%end if%>
<th class="text-right all">Total</th>
</tr>
</thead>
<tbody>
<%
RowTotal = 0
GrandTotal = 0
Striped = False
if isarray(vntData) then
dim table
dim ShowRow
for intX = 0 to ubound(vntData,2)
HideRow = ""
HideClass = ""
ShowRow = true
table = ""
if intX > 0 then
'- write the value
if intX MOD (DateDiff("d", StartDate, EndDate) + 1) = 0 then
'Total Column
if RowTotal > 0 then
table = table & "<td class=""text-right""><font color=#006aa6>" & formatNumber(RowTotal,2) & "</font></td>"
elseif RowTotal < 0 then
table = table & "<td class=""text-right""><font color=#CC0000>" & formatNumber(RowTotal,2) & "</font></td>"
else
table = table & "<td class=""text-right""><font color=#333333>" & formatNumber(RowTotal,2) & "</font></td>"
end if
'Total Column
GrandTotal = GrandTotal + RowTotal
table = table & "</tr>"
RowTotal = 0
table = table & "<tr class=""r"">"
table = table & "<td>" & vntData(0,intX) & "</td>"
end if
if vntData(2,intX) + vntData(3,intX) - vntData(4,intX) > 0 then
table = table & "<TD class=""text-right""><font color=#006aa6>" & formatNumber(vntData(2,intX) + vntData(3,intX) - vntData(4,intX),2) & "</font></td>"
RowTotal = RowTotal + (vntData(2,intX) + vntData(3,intX) - vntData(4,intX))
ColTotal(intX MOD (DateDiff("d", StartDate, EndDate) +1)) = ColTotal(intX MOD (DateDiff("d", StartDate, EndDate) +1)) + (vntData(2,intX) + vntData(3,intX) - vntData(4,intX))
elseif vntData(2,intX) + vntData(3,intX) - vntData(4,intX) < 0 and Overs = "on" then
table = table & "<td class=""redfont text-right"">" & formatNumber(vntData(2,intX) + vntData(3,intX) - vntData(4,intX),2) & "</td>"
RowTotal = RowTotal + (vntData(2,intX) + vntData(3,intX) - vntData(4,intX))
ColTotal(intX MOD (DateDiff("d", StartDate, EndDate) +1)) = ColTotal(intX MOD (DateDiff("d", StartDate, EndDate) +1)) + (vntData(2,intX) + vntData(3,intX) - vntData(4,intX))
elseif vntData(2,intX) + vntData(3,intX) - vntData(4,intX) < 0 and Overs = "" then
table = table & "<td class=""text-right"">0.00</td>"
RowTotal = RowTotal + (0.00)
ColTotal(intX MOD (DateDiff("d", StartDate, EndDate) +1)) = ColTotal(intX MOD (DateDiff("d", StartDate, EndDate) +1)) + (0.00)
else
table = table & "<td class=""text-right"">" & formatNumber(vntData(2,intX) + vntData(3,intX) - vntData(4,intX),2) & "</td>"
end if
else
' First row
table = table & "<tr class=""r"">"
table = table & "<td>" & vntData(0,intX) & "</td>"
if vntData(2,intX) + vntData(3,intX) - vntData(4,intX) > 0 then
table = table & "<td class=""text-right"">" & formatNumber(vntData(2,intX) + vntData(3,intX) - vntData(4,intX),2) & "</td>"
RowTotal = vntData(2,intX) + vntData(3,intX) - vntData(4,intX)
ColTotal(0) = vntData(2,intX) + vntData(3,intX) - vntData(4,intX)
elseif vntData(2,intX) + vntData(3,intX) - vntData(4,intX) < 0 and Overs = "on" then
table = table & "<TD class=""redfont text-right"">" & formatNumber(vntData(2,intX) + vntData(3,intX) - vntData(4,intX),2) & "</td>"
RowTotal = vntData(2,intX) + vntData(3,intX) - vntData(4,intX)
ColTotal(0) = vntData(2,intX) + vntData(3,intX) - vntData(4,intX)
elseif vntData(2,intX) + vntData(3,intX) - vntData(4,intX) < 0 and Overs = "" then
table = table & "<td class=""text-right"">0.00</td>"
RowTotal = RowTotal + (0.00)
ColTotal(0) = ColTotal(0) + (0.00)
else
table = table & "<td class=""text-right"">" & formatNumber(vntData(2,intX) + vntData(3,intX) - vntData(4,intX),2) & "</td>"
end if
end if
response.write(table)
next
tableF = ""
' last row row total
'Total Column
if RowTotal > 0 then
tableF = tableF & "<td class=""text-right""><font color=#006aa6>" & formatNumber(RowTotal,2) & "</font></td>"
elseif RowTotal < 0 then
tableF = tableF & "<td class=""text-right""><font color=#CC0000>" & formatNumber(RowTotal,2) & "</font></td>"
else
tableF = tableF & "<td class=""text-right""><font color=#333333>" & formatNumber(RowTotal,2) & "</font></td>"
end if
'Total Column
GrandTotal = GrandTotal + RowTotal
tableF = tableF & "</tr>"
response.write(tableF)
%>
</tbody>
<tfoot>
<tr class="totals">
<td>Totals:</td>
<%for intX = 0 to DateDiff("d", StartDate, EndDate)%>
<td><%=formatNumber(ColTotal(intX MOD (DateDiff("d", StartDate, EndDate) +1)),2)%></td>
<%next%>
<td><%=formatNumber(GrandTotal,2)%></td>
</tr>
</tfoot>
<%end if%>
</table>