隱藏/顯示列后,邊距表數據自行增加。此結果在顯示/隱藏列之前。之后,我顯示/隱藏 10++ 次數據表 CSS 設置默認值table.dataTable { width: 100%; margin: 0 auto;}它從 5 開始,每次顯示或隱藏時加 1。我多次點擊后終于沒有人阻止它我的劇本var table = $('#table-result').DataTable({ responsive: true, lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]], dom: 'Blfrtip', buttons: [ { extend: 'collection', text: 'Export', buttons: [ 'copy', { extend: 'excel', title: titleExport }, { extend: 'csv', title: titleExport }, { extend: 'pdf', title: titleExport } ] } ], rowReorder: true, columnDefs: [ { orderable: true, className: 'reorder data-table-custom-font', targets: 0 }, { orderable: true, className: 'reorder data-table-custom-font', targets: 1 }, { orderable: false, className: 'data-table-custom-font', targets: '_all' } ] });這個腳本顯示/隱藏列 $('button.toggle-vis').on( 'click', function (e) { e.preventDefault(); // Get the column API object let column = table.column( $(this).attr('data-column') ); console.log($(this).attr('data-column')) // Toggle the visibility column.visible( ! column.visible() ); } );謝謝。如果您還想要更多東西,請告訴我。
隱藏/顯示列后邊距數據表自行增加
墨色風雨
2023-09-28 16:03:01