Showing posts with label datatables.net. Show all posts
Showing posts with label datatables.net. Show all posts

Saturday, March 7, 2020

Datatable.net - Get Reordering of the columns & Get Column visible

Datatable.net - Get Reordering of the columns & Get Column visible

Please add a button on the form like below
<a class="btn btn-success visiblecheck" href="javascript:void(0);" id="visiblecheck" value="test">visiblecheck</a>

Here is 'table' is variable of Datatable.net like

var table = $('#example').dataTable();


$('.visiblecheck').click(function () {
        alert(table.colReorder.order());
        var columnvisible = '';

        for (i = 0; i < table.columns().count(); i++) {
            if (columnvisible != '') {
                columnvisible += ',';
            }
            if (table.column(i).visible() === true) {
                columnvisible += '1';
            }
            else {
                columnvisible += '0';
            }
        }
        alert(columnvisible);
    });


table.colReorder.order() -  this will return the ordering of columns

Monday, August 19, 2019

DataTables warning: table id=table1 - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3

Issue - DataTables warning: table id=table1 - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3

Solution -
This error can often occur when trying to obtain a reference to the DataTable for working with the API. For example, you might have a function which will always try to create a DataTable instance by passing in options when created. Then you make a modification which calls this function on a table which has already been initialised and you get this error.
In such a case, you will want to use the $.fn.dataTable.isDataTable() static method. This can be used to check if a table is a DataTable or not already:
1
2
3
4
5
6
7
8
if ( $.fn.dataTable.isDataTable( '#table1' ) ) {
    table = $('#table1').DataTable();
}
else {
    table = $('#table1').DataTable( {
        paging: false
    } );
}

for more information please visit the page - https://datatables.net/manual/tech-notes/3