php - 如果表数据是动态的并且可能最多两个维度,如何将 rowspan 和 colspan 与数据表一起使用?
问题描述
我在 laravel 项目中使用数据表。需要从数据库中获取记录,可能最多两个维度。如何使用 rowspan 或 colspan 使记录类别组具有分页和 pageLength 功能?
这个项目在 laravel 框架 5.5 上工作。php >=7.0 版本和 MySQL 5.0.
我也尝试过数据表的rowGroup。但它有一些限制,例如:
目前一次只能使用一个数据点进行分组 - 不支持嵌套分组
没有展开/折叠组的选项
不支持 Buttons 扩展的导出选项 - 分组信息被忽略。
var table = $('#report-employee-table').DataTable({
pageLength: 20,
processing: true,
serverSide: true,
bLengthChange: false,
dom: 'Blfrtip',
buttons: [{
extend: 'excelHtml5',
"text": '<span class="glyphicons glyphicons-file_export"></span> Export',
"title": 'Employee Report',
"message": 'Employee Name: ' + $('#employee_id option:selected').text() + ' Work Duration: ' + $('#report_date').val(),
"filename": 'employee-report',
header: true,
footer: true,
exportOptions: {
modifier: {
selected: true
}
},
customize: function (xlsx) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
// s = for styling and 5 will make it left align with grey background
$('row:first c', sheet).attr('s', '5');
}
},
{
extend: 'print',
"text": '<span class="fa fa-print"></span> Print',
"title": 'Employee Report',
"message": 'Employee Name: ' + $('#employee_name option:selected').text() + ' Work Duration: ' + $('#report_date').val(),
"filename": 'employee-report',
header: true,
footer: true,
exportOptions: {
modifier: {
selected: true
}
}
}
],
ajax: {
url: "/*URL of controller where function return data in json format*/",
data: function (d) {
d.employee_name = $('#employee_name').val();
d.report_date = $('#report_date').val();
}
},
columns: [
//{data: 'DT_Row_Index', name: 'DT_Row_Index'},
{
data: 'project_name',
name: 'project_name'
},
{
data: 'work_type_name',
name: 'work_type_name'
},
{
data: 'total_hour',
name: 'total_hour'
},
],
rowsGroup: ['project_name:name', 0],
footerCallback: function (row, data, start, end, display) {
var api = this.api();
var aCol = api.column(2);
var foo = aCol.data(); //is empty!
$(aCol.footer()).html(
);
},
});
解决方案
推荐阅读
- ruby - 如何处理来自外部文件的 Sinatra 错误?
- python - 解析 XML 并转换为 CSV python
- julia - 情节.vline!在新的 Plots 版本中无法识别函数
- flutter - 如何在构造时在状态类中使用有状态的小部件参数而不将小部件添加到树中?
- javascript - 地图上没有出现点的图层 OpenLayers
- asp.net-core - 如何在发送响应之前获取防伪令牌?
- c - 将类型 int 乘以 struct 时出错
- network-programming - 去中心化点对点
- flutter - 约束定位小部件的堆栈区域
- google-cloud-platform - 在 BigQuery 中的多个表上运行更新