[英]How to add footer row in a JTable
How to add footer row in Jtable , i am using jTable 2.4.0 version js files and mvc 4. 如何在Jtable中添加页脚行,我正在使用jTable 2.4.0版本的js文件和mvc 4。
Reference 参考
Samir you can use the jquery.jtable.footer.js jtable extension from https://github.com/gbisheimer/jtable/tree/master/lib/extensions . Samir您可以使用https://github.com/gbisheimer/jtable/tree/master/lib/extensions中的jquery.jtable.footer.js jtable扩展名。
and configure you column for footer as shown below 并为页脚配置页脚,如下所示
Balance: {
title: 'Balance',
width: '70',
create:false,
edit: false,
display: function (data) {
return "£ " + data.record.Balance;
},
footer: function (data) {
var total = 0;
$.each(data.Records, function (index, record) {
total = Number(record.Balance);
});
return ("£"+total.toFixed(2));
}
}
Am using footer.js file 我正在使用footer.js文件
https://github.com/sheryever/jtable/blob/master/lib/extensions/jquery.jtable.footer.js https://github.com/sheryever/jtable/blob/master/lib/extensions/jquery.jtable.footer.js
see more jtable extension 查看更多jtable扩展
https://github.com/sheryever/jtable/tree/master/lib/extensions https://github.com/sheryever/jtable/tree/master/lib/extensions
I have implemented this for my jtable and came across an issue with hidden columns and the footer fields not lining up correctly. 我已经为我的jtable实现了此功能,并遇到了隐藏列和页脚字段未正确对齐的问题。 I specifically include the ID column as the first column within the table but set its visibility to hidden within the jtable definition.
我专门将ID列作为表的第一列包括在内,但将其可见性设置为在jtable定义中隐藏。
I overcame this with a couple of minor edits (one to the class file and one to the base jtable file, I am not sure if this could be rolled into the class file to make it more complete and not be broken by base class updates) 我通过一些较小的修改克服了这一点(一次修改到类文件,一次修改到基本jtable文件,我不确定是否可以将其滚动到类文件中以使其更加完整并且不会被基类更新破坏)
modified class extension file: 修改后的类扩展文件:
_createFooterCellForField: function (fieldName, field) {
var style = "";
if(field.visibility == 'hidden') style = ' style="display: none;" ';
return $('<th class="jtable-column-footer" '+style+'>' +
'<div class="jtable-column-footer-container"><span class="jtable-column-footer-text"></span></div></th>');
}
This still puts a footer table cell into the DOM but hides it should the column be hidden from initial configuration 这仍然将页脚表单元格放入DOM中,但是如果从初始配置中隐藏了该列,则将其隐藏
modified base class file: 修改后的基类文件:
changed: 已更改:
.find('>thead >tr >th:nth-child(' + columnIndexInTable + '),>tbody >tr >td:nth-child(' + columnIndexInTable + ')')
to become: 成为:
.find('>thead >tr >th:nth-child(' + columnIndexInTable + '),>tbody >tr >td:nth-child(' + columnIndexInTable + '),>tfoot >tr >th:nth-child(' + columnIndexInTable + ')')
twice within the base class to hide/show the footer cell as well as the rest of the column if you select the column via the right click context menu. 如果您通过右键单击上下文菜单选择列,则在基类中两次隐藏/显示页脚单元以及列的其余部分。 These edits were done within the
_changeColumnVisibilityInternal: function (columnName, visibility) {
function around line 4500 这些编辑是在
_changeColumnVisibilityInternal: function (columnName, visibility) {
函数在4500行左右进行的
Also in the example above your total formula is slightly incorrect, should be total += Number(record.Balance);
同样在上面的示例中,您的总公式有点不正确,应该是
total += Number(record.Balance);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.