How to customize the layout ?

How to customize the layout ?

mohambomohambo Posts: 2Questions: 1Answers: 0
edited May 28 in Free community support

DataTables warning: table id=DataTables_Table_0 - Cannot reinitialise DataTable. For more information about this error, please see https://datatables.net/tn/3':
**Hello, i'm using datatables v2 and i want to customize the layout , i tried the following in a separate js file :
jQuery(document).ready(function($){
$('.table').DataTable({
layout: {
topStart: 'search',
topEnd: null,
bottomEnd: {
paging: {
type: 'simple_numbers'
}
},
bottomStart: {
pageLength: {
menu: [10, 25, 50, 100]
}
}
}
});
})
but got the following error : DataTables warning: table id=DataTables_Table_0 - Cannot reinitialise DataTable. For more information about this error, please see https://datatables.net/tn/3' **:

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    As the error says, you are initialising DataTables twice. If you look at the tech note linked in the error message, you'll see how to combine two different initialisation objects into one.

    If that doesn't resolve it, please link to a test case as the forum rules require, and the new post template text that you deleted.

    Allan

  • mohambomohambo Posts: 2Questions: 1Answers: 0

    **https://live.datatables.net/zewetoki/20/edit?html,css,js,console,output**:
    I already did as suggested in the note before posting here but sadly did not work , still got the same error message, i'm not using datatables js file so it's first included in the html then the custome layout js file, i'm trying to get the fisrt instance created of dt, so i can alter the layout , above is the similare resulat i look for , thanx for any help

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Exactly as Allan said - you have "$('#example').DataTable({" twice. You can't do that.
    Either move your layout settings into the script inside your HTML, or combine your HTML script with your external one.

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    The var table = new DataTable(); you have as the first statement is initializing the Datatable with default values. This following code:

    $('#example').DataTable({
      layout: {
          topStart: 'pageLength',
          topEnd: 'search',
          bottomStart: 'info',
          bottomEnd: 'paging'
        },
    });
    

    Is then trying to reinitialize causing the error you see.

    Wait the same error is occurring. I found you have another Datatables initialization at the bottom of the HTML tab :smile: I'm not sure I understand why you have the above code as that is the default layout setting. If you are trying to assing the table variable with the Datatable API then do it with the full init code, like this updated test case:
    https://live.datatables.net/gazavowi/1/edit

    Kevin

Sign In or Register to comment.