DataTables.net初始化时更改动态列更改索引顺序

时间:2017-12-01 08:51:07

标签: jquery html datatable

希望有人可以帮助我,因为我还在了解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&nbsp;463.30</td>
            <td>11&nbsp;351.90</td>
            <td>29&nbsp;513.00</td>
            <td>13&nbsp;642.50</td>
            <td>0.00</td>
            <td>67&nbsp;970.70</td>
        </tr>
        <tr>
            <td>[16] ADDED-16-Feb-2017</td>
            <td>10&nbsp;791.60</td>
            <td>3&nbsp;237.80</td>
            <td>14&nbsp;054.80</td>
            <td>15&nbsp;547.90</td>
            <td>0.00</td>
            <td>43&nbsp;632.10</td>
        </tr>
        <tr>
            <td>[17] ADDED-18-Jul-2016</td>
            <td>20&nbsp;021.60</td>
            <td>14&nbsp;083.30</td>
            <td>23&nbsp;634.40</td>
            <td>19&nbsp;115.50</td>
            <td>10&nbsp;230.20</td>
            <td>87&nbsp;085.00</td>
        </tr>
        <tr>
            <td>[2] AAPSTERT</td>
            <td>20&nbsp;544.40</td>
            <td>14&nbsp;900.00</td>
            <td>23&nbsp;156.30</td>
            <td>13&nbsp;131.40</td>
            <td>0.00</td>
            <td>71&nbsp;732.10</td>
        </tr>
        <tr>
            <td>[3] JANA</td>
            <td>11&nbsp;883.30</td>
            <td>14&nbsp;948.10</td>
            <td>12&nbsp;525.10</td>
            <td>15&nbsp;934.10</td>
            <td>6&nbsp;824.20</td>
            <td>62&nbsp;114.80</td>
        </tr>
        <tr>
            <td>[31] ADDED-8-Apr-2016</td>
            <td>32&nbsp;813.50</td>
            <td>36&nbsp;833.40</td>
            <td>33&nbsp;099.10</td>
            <td>17&nbsp;500.70</td>
            <td>4&nbsp;295.00</td>
            <td>124&nbsp;541.70</td>
        </tr>
        <tr>
            <td>[51] ADDED-16-Feb-2017</td>
            <td>6&nbsp;235.10</td>
            <td>8&nbsp;213.40</td>
            <td>14&nbsp;132.40</td>
            <td>8&nbsp;996.70</td>
            <td>6&nbsp;105.30</td>
            <td>43&nbsp;682.90</td>
        </tr>
        <tr>
            <td>[52] ADDED-16-Feb-2017</td>
            <td>5&nbsp;425.30</td>
            <td>5&nbsp;422.80</td>
            <td>7&nbsp;295.80</td>
            <td>6&nbsp;439.40</td>
            <td>6&nbsp;458.80</td>
            <td>31&nbsp;042.10</td>
        </tr>
        <tr>
            <td>[6] ADDED-28-Jul-2016</td>
            <td>10&nbsp;088.90</td>
            <td>15&nbsp;562.90</td>
            <td>17&nbsp;760.70</td>
            <td>11&nbsp;091.20</td>
            <td>0.00</td>
            <td>54&nbsp;503.70</td>
        </tr>
        <tr>
            <td>[61] ADDED-16-Feb-2017</td>
            <td>8&nbsp;346.80</td>
            <td>5&nbsp;448.00</td>
            <td>16&nbsp;083.60</td>
            <td>14&nbsp;548.20</td>
            <td>16&nbsp;670.60</td>
            <td>61&nbsp;097.20</td>
        </tr>
        <tr>
            <td>[71] ADDED-28-Aug-2017</td>
            <td>18&nbsp;956.10</td>
            <td>11&nbsp;652.70</td>
            <td>24&nbsp;738.00</td>
            <td>11&nbsp;238.70</td>
            <td>7&nbsp;665.90</td>
            <td>74&nbsp;251.40</td>
        </tr>
        <tr>
            <td>[72] ADDED-8-Apr-2016</td>
            <td>12&nbsp;277.10</td>
            <td>8&nbsp;489.90</td>
            <td>13&nbsp;718.10</td>
            <td>9&nbsp;860.70</td>
            <td>9&nbsp;619.10</td>
            <td>53&nbsp;964.90</td>
        </tr>
    </tbody>
    <tfoot>
        <tr class="totals">
            <td>Totals:</td>
            <td>170&nbsp;847.00</td>
            <td>150&nbsp;144.20</td>
            <td>229&nbsp;711.30</td>
            <td>157&nbsp;047.00</td>
            <td>67&nbsp;869.10</td>
            <td>775&nbsp;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>

0 个答案:

没有答案