DataTable按鈕,排序,單元格顏色
阿新 • • 發佈:2018-11-15
function init_ceph_table(data, elementid) { var table = $('#' + elementid).DataTable( { data: data, columns: [ {data: "host"}, {data: "disk_slot"}, {data: "disk_score"}, {data: "disk_media_error_count"}, {data: "disk_other_error_count"}, {data: "disk_pred_fail_count"}, {data: "disk_reallocated_sector_count"}, {data: "volume"}, {data: "osd_state"} ], "columnDefs": [{ "targets": 2, "createdCell": function (td, cellData, rowData, row, col) { if (cellData <100) $(td).css('color', 'red'); } }], buttons: [ { extend: 'copy', text: '複製' }, { extend: 'excel', text: '匯出excel' } ], "order": [[2, "asc"]], paging: false, "language": { "sProcessing": "處理中...", "sLengthMenu": "顯示 _MENU_ 項結果", "sZeroRecords": "沒有匹配結果", "sInfo": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項", "sInfoEmpty": "顯示第 0 至 0 項結果,共 0 項", "sInfoFiltered": "(由 _MAX_ 項結果過濾)", "sInfoPostFix": "", "sSearch": "搜尋:", "sUrl": "", "sEmptyTable": "表中資料為空", "sLoadingRecords": "載入中...", "sInfoThousands": ",", "oPaginate": { "sFirst": "首頁", "sPrevious": "上頁", "sNext": "下頁", "sLast": "末頁" }, "oAria": { "sSortAscending": ": 以升序排列此列", "sSortDescending": ": 以降序排列此列" } } } ); table.buttons().container() .appendTo($('.col-sm-6:eq(0)', table.table().container())); }
表頭在table中直接定義