根据列数设置datatable列

时间:2018-12-10 07:22:39

标签: javascript jquery datatable datatables

我有一个带有灵活列的数据表。有时该列是五(5),有时是三(3),具体取决于用户访问权限。下面是我的js。我的代码的逻辑是这样的:如果用户无权删除或更新未生成列的数据。这使我的js错误。如何根据列数设置列宽?

$('#town-table').DataTable({
       "searching": { "regex": true },
        "bLengthChange": false,
        "scrollY":"500px",
        "scrollX":"300px",
        "scrollCollapse": true,
        "paging": true,
        "autoWidth": false,
        "processing": true,
        "serverSide": true,
        "autoWidth": true,
        "ajax": {
            url: "admin-town-table-data.php",
            type: "POST",
            "dataType": "json",
            "complete": function(response) {
                console.log(response);
            }
        },
         "columnDefs": [
            { "orderable": false, "targets": 3 },
            { "orderable": false, "targets": 4 }
        ],
        "language": {
            "emptyTable": "No data available in table",
            "zeroRecords": "No data available in table",
            "info": "Showing <b>_START_</b> to <b>_END_ of _TOTAL_</b> entries",
            "paginate": {
                "first":      "First",
                "last":       "Last",
                "next":       "Next",
                "previous":   "Previous"
            },
            search: "_INPUT_",
            searchPlaceholder: "Search..."
        },
        dom: 'Bfrtip',
        buttons: [
            'csv', 'excel', 'pdf'
        ]
    });

0 个答案:

没有答案