Jquery 正在绘制两次响应数据表
表定义Jquery 正在绘制两次响应数据表,jquery,datatables,laravel-5.5,Jquery,Datatables,Laravel 5.5,表定义 <table id="planRouteTable" class="table table-striped table-hover table-bordered responsive"> <thead> <tr> <th>Type</th> ....other columns.... </
<table id="planRouteTable" class="table table-striped table-hover table-bordered responsive">
<thead>
<tr>
<th>Type</th>
....other columns....
</tr>
</thead>
</table>
初始化
let options=$.extend({},window.bp.baseDataTableOptions{
阿贾克斯:{
url:window.bp.apiPath+“指定检查的数据表/用户”
},
栏目:[
{data:'policy_type',name:'policy_type',className:'text center',orderable:false},
/*其他栏目*/
{
目标:-1,
数据:空,
类名:“文本权限”,
可订购:错误,
默认内容:`
添加到路线
`
}
]
});
$(#planRouteTable')。数据表(选项);
我遇到的问题是,每当table
元素添加了responsive
类,以便启用DataTables的响应版本时,它会绘制两次。通常情况下,我不会在意,但由于这是在服务器端呈现的,它会两次命中API端点,并随机触发服务器的401
响应
服务器端呈现由插件处理。从2.2版开始,这是一个bug : 恐怕这是2.2.0版的Responsive中的一个bug。使用 将在下一版本之前解决此问题。我给它贴标签 一旦这件事频繁发生 So 2选项: 等待正式标签,或:
bower install https://nightly.datatables.net/responsive/js/dataTables.responsive.min.js
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);
bower install https://nightly.datatables.net/responsive/js/dataTables.responsive.min.js