【问题标题】:Responsive DataTables being drawn twice响应数据表被绘制两次
【发布时间】: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


    【解决方案1】:

    这是 2.2 版的一个错误

    From the developer:

    恐怕这是 2.2.0 版本的响应式的错误。使用 nightly version 将在下一个版本之前解决它。我会标记它 很快就会出现这种情况。

    所以 2 个选项:

    等待官方标签,或者:

    bower install https://nightly.datatables.net/responsive/js/dataTables.responsive.min.js
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多