【发布时间】:2017-09-27 21:17:21
【问题描述】:
表定义...
<table id="planRouteTable" class="table table-striped table-hover table-bordered responsive">
<thead>
<tr>
<th>Type</th>
....other columns....
</tr>
</thead>
</table>
JS 定义
基本选项
baseDataTableOptions: {
processing: true,
serverSide: true,
responsive: true,
pageLength: 25
},
初始化
let options = $.extend({}, window.bp.baseDataTableOptions, {
ajax: {
url: window.bp.apiPath + 'data-tables/users-assigned-inspections'
},
columns: [
{ data: 'policy_type', name: 'policy_type', className: 'text-center', orderable: false },
/* Other columns */
{
target: -1,
data: null,
className: "text-right",
orderable: false,
defaultContent: `
<button class="[ btn btn-primary ]">Add to Route</button>
`
}
]
});
$('#planRouteTable').DataTable(options);
我遇到的问题是,每当table 元素添加了responsive 类以便启用DataTables 的响应版本时,它就会绘制两次。通常情况下,我不会在意,但由于这是在服务器端呈现的,因此它会两次访问 API 端点并随机触发来自服务器的 401 响应。
服务器端渲染由Laravel DataTables 插件处理。
【问题讨论】:
标签: jquery datatables laravel-5.5