javascript - 制表符,有没有办法在页脚中添加页面总和?
问题描述
Tabulator
有一个名为Column Calculations
.
我需要同时添加sum of page
和sum of total
例如,我可以为计算添加页脚sum of total
,但我不能同时添加sum of visible rows
或换句话说sum of current page only
。
bottom
我可以在表格或表格中添加页脚top
:topCalc
& bottomCalc
。
例如我可以sum
添加price
添加
正如您在下面的示例中看到的,我在这里添加了价格总和。
我也把例子放在这里:https ://jsfiddle.net/o2ycm5dp/
function generateTable(data) {
tableInstance = new Tabulator("#simpleTable", {
layout: "fitColumns",
resizableColumns: false,
selectable: false,
paginationSize: 3,
responsiveLayout: "hide",
ajaxFiltering: false,
pagination: "local",
columns: [{
title: "name",
field: "name",
},
{
title: "price",
field: "price",
bottomCalc: "sum",
},
],
});
tableInstance.setData(data);
}
$(document).ready(function() {
var data = [{
name: "Tiger Nixon",
price: "320800"
}, {
name: "Garrett Winters",
price: "170750"
}, {
name: "Ashton Cox",
price: "86000"
}, {
name: "Cedric Kelly",
price: "433060"
}, {
name: "Airi Satou",
price: "162700"
}, {
name: "Brielle Williamson",
price: "372000"
}, {
name: "Herrod Chandler",
price: "137500"
}];
generateTable(data);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://unpkg.com/tabulator-tables@4.5.3/dist/css/tabulator.min.css" rel="stylesheet">
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@4.5.3/dist/js/tabulator.min.js"></script>
<div id="simpleTable"></div>
在这一行 : bottomCalc: "sum",
,将调用计算函数,我们可以sum
看到price
列。
有一个名为的选项Custom Calculations
,我可以添加一个函数来计算current page values
,但我不能计算total pages values
.
另一种解决方案可能append
是页脚的 html 元素,但我认为这不是一个好的解决方案。因为我应该处理所有与Tabulator
页脚相关的功能。
解决方案
Tabulator 无法按您的要求布置表格。您需要手动创建一个页脚元素来处理此问题,然后使用分页回调来计算要显示的值
推荐阅读
- windows - IIS 服务器和客户端
- php - 未定义变量:Laravel 中的访问者
- nginx - nginx 将 /api 重写为 SPA 的根域(单页应用程序)
- javascript - 在 Firestore 中调用函数时未定义的值
- laravel - Laravel 5.7,如何在 Laravel 中解密或查看哈希密码?
- python-3.x - 在下一个对象中追加重复
- python - Python - 使用网络抓取下载视频
- c# - 单击选定的组合框第一个文本框。Focus() 在 C# 中工作不完整
- python - 在类定义参数中调用 self.variable(在 __init__() 中建立)
- javascript - 未捕获的引用错误:未定义 BookingData - 其中“BookingData”是 Firebase 中收集器的名称