Quantcast
Channel: DataTables 1.9 — DataTables forums
Viewing all articles
Browse latest Browse all 124

Re-initialize dataTable from fnServerData

$
0
0

Datatable is being initialized with 2 ajax calls: table structure (columns) and table data.
Structure data is being cached.

Case:
User removes last records from table
Table being initialized (reDrawn)
Re-cache table structure

    // 1) Get table structure
    // 2) render table 
    // 3) initialize dataTable
// If there are any records, structure is cached in localStorage()
function setupTable() {
    function getStructure() {

      if (response.iTotalRecords > 0) 
        localStorage.setItem(structureName, JSON.stringify(response));

    }
    oTable.renderTable(); // render table structure in document
    oTable.initTable();
}

function initTable() {  
    function fnServerData() {
      // If has cached structure but doesn't have records
              // -> setup dataTable with fresh structure
          if (iTotalRecords === 0 && hasCachedStructure()) {

      // step 1) Remove old cached structure
      localStorage.removeItem(structureName);

       // step 2) Destroy table before initializing it again
       oTable.fnDestroy();

       // step 3) Get new structure and initialize datatable with new structure
       setupTable();

      }
    } 
}

The issue is that dataTable controls (column, pagination, footer info) is not being destroyed.
How can I do clean table destruction and setup table from start?

Thank you for your time and any guidance.


Viewing all articles
Browse latest Browse all 124

Trending Articles