【发布时间】:2015-01-13 03:05:50
【问题描述】:
我正在使用 Datatables 创建一个按数据分组的网格。我能够对我的表进行分组。
我想将条目总数作为分组行数而不是作为总条目数,我该怎么做?
上图中突出显示的部分应显示“显示 8 个条目中的 1 到 8 个”,因为有 8 个组。
请参考我的小提琴 - http://jsfiddle.net/hh4kq5y0/
$(document).ready(function () {
$('#example').dataTable({
"bLengthChange": false,
"bPaginate": false,
"bJQueryUI": true
}).rowGrouping({
bExpandableGrouping: true,
bExpandSingleGroup: false,
iExpandGroupOffset: -1,
asExpandedGroups: [""]
});
GridRowCount();
});
function GridRowCount() {
$('span.rowCount-grid').remove();
$('input.expandedOrCollapsedGroup').remove();
$('.dataTables_wrapper').find('[id|=group-id]').each(function () {
var rowCount = $(this).nextUntil('[id|=group-id]').length;
$(this).find('td').append($('<span />', { 'class': 'rowCount-grid' }).append($('<b />', { 'text': rowCount })));
});
$('.dataTables_wrapper').find('.dataTables_filter').append($('<input />', { 'type': 'button', 'class': 'expandedOrCollapsedGroup collapsed', 'value': 'Expanded All Group' }));
$('.expandedOrCollapsedGroup').live('click', function () {
if ($(this).hasClass('collapsed')) {
$(this).addClass('expanded').removeClass('collapsed').val('Collapse All Group').parents('.dataTables_wrapper').find('.collapsed-group').trigger('click');
}
else {
$(this).addClass('collapsed').removeClass('expanded').val('Expanded All Group').parents('.dataTables_wrapper').find('.expanded-group').trigger('click');
}
});
};
谢谢
【问题讨论】:
标签: javascript jquery datatables jquery-datatables