gpt4 book ai didi

javascript - 在制表符中显示行数

转载 作者:行者123 更新时间:2023-12-02 00:03:54 25 4
gpt4 key购买 nike

在 DataTables 中,我们具有显示第 1 行(共 100 行)的功能。我想在制表符中做相同或相似的事情。我使用了这种方法,它返回空表:

JavaScript

var tabulator_table = new Tabulator("#example", {
columns: [
{ title: "", field: "", headerFilter: "input" },
{ title: "", field: "", headerFilter: "input" },
{ title: "", field: "", headerFilter: "input" },
{ title: "", field: "", headerFilter: "input" },
{ title: "", field: "", headerFilter: "input" },
{ title: "", field: "", headerFilter: "input" },
],
//this part should return row count
dataFiltered: function (data, field, type, value) {
//data - the subset of the total table data that has passed the filter and is now visible
//field - the field being filtered
//type - the type of filter being used
//value - the value of the filter

//set text in info element to show the number of rows and filters currently applied
$("#example-table-info").text("rows:" + data.length + " of " + $("#tableID").Tabulator("getData").length +
", filter:" + field + type + value);
}
});

HTML

<div class="footer">
<p id="example-table-info"></p>
<div id="myButtons"> Export </div>
</div>

错误是:“制表符不是函数”

我也尝试过使用另一种方法:JavaScript

function myFunction() {
return $('tr', $(this).find('tbody')).length;
}

rowctr = $('#tableID').rowCount();
document.getElementById("demo").innerHTML = myFunction();

HTML

<p id="demo"></p>

我也在他们的 github 上看到使用这个:

var activeRowCount = table.getDataCount(true);

但我不知道如何或在何处应用它并在我的页脚标记中返回值。谢谢。

最佳答案

经过研究和帮助,这是我所做的:

JavaScript

var tabulator_table = new Tabulator("#example", {
columns: [
{ title: "", field: "", bottomCalc: "count", headerFilter: "input" },
{ title: "", field: "", bottomCalc: "count", headerFilter: "input" },
{ title: "", field: "", bottomCalc: "count", headerFilter: "input" },
{ title: "", field: "", bottomCalc: "count",headerFilter: "input" },
{ title: "", field: "", bottomCalc: "count", headerFilter: "input" },
{ title: "", field: "", bottomCalc: "count", headerFilter: "input" },
],
dataFiltered: function(filters, rows) {
var el = document.getElementById("search_count");
el.innerHTML = rows.length;
},
dataLoaded: function(data) {
var el = document.getElementById("total_count");
el.innerHTML = data.length;
},
});

var total_count = $(".tabulator-footer").find('.tabulator-cell:first-child()').text();
$("#total_count").text(total_count);
//rest of your js if you have any.

CSS

.tabulator-footer {
display: none;
}

HTML

<span style="color:#102D4F;font-size:12px;font-family:Arial, Helvetica, sans-serif">
Showing <span id="search_count"></span> results in total <span id="total_count"></span>
</span>

关于javascript - 在制表符中显示行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61209171/

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