仅在显示所有条目时显示页脚

时间:2015-10-02 11:56:05

标签: jquery html datatables

我已经使用jQuery DataTables几天了,只有在显示所有条目时我才需要显示页脚。

例如,如果我的表格中有18个数据行并且被选中显示9,则页脚不应该是可见的;如果显示所有18,则页脚应该可见。

目前,Datatable页脚的代码如下所示:

<tfoot>
    <tr>
       <th colspan="1" style="text-align:left">Round: </th>
       <th style="text-align:center"></th>
       <th style="text-align:center"></th>
     </tr>

它的JS代码:

$("#TableDt" + rid).DataTable({
    "lengthMenu": [[18, 9], [18, 9]],
    bFilter: false,
    "footerCallback": function (row, data, start, end, display) {
        var api = this.api(), data;
        // Remove the formatting to get integer data for summation
        var intVal = function (i) {
            var alb3;
            if (typeof i == 'string') {
                var alb = i.split(">");
                var alb2 = alb[1].split("<");
                alb3 = parseInt(alb2[0]);
            }
            else if (typeof i === 'number')
                alb3 = i;
            else
                alb3 = 0;
            return alb3;
        };
        // Total over all pages
        totalT = api
            .column(2)
            .data()
            .reduce(function (a, b) {
                return intVal(a) + intVal(b);
            });
        totalP = api
            .column(1)
            .data()
            .reduce(function (a, b) {
                return intVal(a) + intVal(b);
            });
        var TimeP = 0;
        var TimeT = 0;

        var time = totalP;
        var time2 = totalT;
        var h1 = Math.floor(time / 60);
        var m1 = time % 60;
        var h2 = Math.floor(time2 / 60);
        var m2 = time2 % 60;
        if (h1 <= 9) {
            if (m1 <= 9)
                TimeP = '0' + h1 + ':0' + m1;
            else
                TimeP = '0' + h1 + ':' + m1;
        }
        else if (m1 <= 9)
            TimeP = h1 + ':0' + m1;
        else
            TimeP = h1 + ':' + m1;
        if (h2 <= 9) {
            if (m2 <= 9)
                TimeT = '0' + h2 + ':0' + m2;
            else
                TimeT = '0' + h2 + ':' + m2;
        }
        else if (m2 <= 9)
            TimeT = h2 + ':0' + m2;
        else
            TimeT = h2 + ':' + m2;

        $(api.column(1).footer()).html(
            '' + TimeP + ''
        );
        $(api.column(2).footer()).html(
            '' + TimeT + ''
        );
    }
});

我没有找到任何可以帮助我的东西。只有在显示所有行时才可以显示它?

1 个答案:

答案 0 :(得分:1)

  

<强>解

您可以在$docLinkFile = "c:\temp\urls.csv" $webclient = New-Object System.Net.WebClient $webclient.Credentials = $cred $TargetDirectory = "\\NRP-12-62-3\Root\NV-RST\Southwest Projects\Marketing Analysis\Monthly Sales Reports" $subDirectoryName = $((Get-Date).ToString('MM-dd-yyyy-HHmmss')) $TargetDirectory = $TargetDirectory + "\" + $subDirectoryName # Create directory $subDirectory = New-Item -ItemType directory -Path $TargetDirectory foreach ($i in Import-Csv $docLinkFile) { $fileURL = $i.DOC_URL Write-Host $fileURL $splitByslash = $fileURL.Split("/") # return the last element of the array $fileName = $splitByslash[-1] Write-Host $fileName -ForegroundColor Green $target = $TargetDirectory + "\" + $fileName if (Test-Path $target) { $existingFileName = [io.path]::GetFileNameWithoutExtension($target) $extension = [io.path]::GetExtension($target) $newFileName = "$TargetDirectory" +"\" + $existingFileName + " - duplicate $(get-date -f HHmmss)" + "" + $extension Write-Host $newFileName $webclient.DownloadFile($fileURL, $newFileName) } else { $webclient.DownloadFile($fileURL, $target) } Start-Sleep -s 1 } 初始化代码之前将处理程序附加到search事件。过滤表时会触发此事件。

然后,您可以使用search()检索搜索查询,并根据查询确定是否显示或隐藏页脚。

DataTable()
  

<强>样本

请参阅this jsFiddle以获取代码和演示。