{hero}

DataTables.Settings

DataTables 設定物件。

描述

DataTables 將每個表格的設定和資料儲存在一個設定物件中。就 DataTables API 而言,此物件的結構被視為私有的,並且不支援讀取或寫入物件中的值。物件內包含的屬性名稱和值在版本之間可能會且將會變更!

基於上述警告,您可能會完全不敢使用該物件,但實際上它可能非常有用。由於它包含完整描述 DataTable 所需的資訊,DataTables 通常會將此物件傳遞到回呼方法中,以提供所討論表格的描述,然後可以將其與 API 建構函式(請參閱 DataTables.Api)一起使用,以建立表格的新 API 物件。例如

var api = new $.fn.dataTable.Api( settings );

上述程式碼會為問題中 settings 物件所參照的表格建立 API 實例。

考慮使用 drawCallback 的更完整範例

new DataTable('#myTable', {
    "drawCallback": function( settings ) {
        var api = new $.fn.dataTable.Api( settings );

        // Output the data for the visible rows to the browser's console
        // You might do something more useful with it!
        console.log( api.rows( {page:'current'} ).data() );
    }
} );