uncaught exception: FixedColumns already initialised on this table

uncaught exception: FixedColumns already initialised on this table

proggy123proggy123 Posts: 4Questions: 1Answers: 0

Hi,

I am currently programming an ajax-based website, which loads ALL its content always via ajax. There are a lot of datatables initialised when surfing through the site, but only one specific table has the fixedColumns option to true.

When I load this table, then load some other stuff into the website (the datatable disappears) and load the pagecontent with this table again, I get this error in my console:

uncaught exception: FixedColumns already initialised on this table

Thing is: all datatables get created through the same js function I wrote, and there the option destroy is set to true. This should prevent the "already initialised" error from popping up, as - if I understand the destroy option correctly - whenever a datatable is already initialised, it will get destroyed and then initialised again, automatically...?

Furthermore, all the tables get saved in an array while created -->

datatables[tid]=$("#"+tid).DataTable( { destroy: true, ....... 

I already tried just manually destroying ALL available tables:

var _tmp=Object.keys(datatables);
$.each(_tmp, function( index,value ) {
    if ($("#"+value).length==1)
        datatables[value].destroy();
});

But still the error pops up. How is that even possible??

If there is no easy answer without reviewing all of my code (there is a lot), is there at least a way catch this error and "UNinitialise" the table on-the-fly?

Thank you for your suggestions!
Marcus

Answers

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin

    Hi Marcus,

    I've just tried to recreate the issue here but it appears to work as expected for me.

    Can you link to a test case showing the issue please.

    Allan

  • proggy123proggy123 Posts: 4Questions: 1Answers: 0

    Hi Allan,

    thank you for your quick reply! Unfortunately, I cannot link to a case, as the script is very large and would need a lot of adjustments in order to work in a smaller environment. I tried recreating the error in a fiddle, but there is also to much script adjustment needed to work.

    However, here is what I know but console-logging the following part:

    console.log("a");
    datatables[tid]=$("#"+tid).DataTable( { 
      destroy: true,
      fixedColumns: true,
      [...]
      "fnDrawCallback":function(){
        console.log("b");
      }
    });
    console.log("c");
    

    the console shows the following:

    a
    b
    b
    uncaught exception: FixedColumns already initialised on this table
    

    So, the drawCallback gets done twice, which seems to be always case when fixedColumns is set to true. But, the last console.log("c") is AFTER the error I am trying to solve.
    Maybe this helps!

    I know, the best way would be to find the source of the error, right now I am mostly interested in solving it quickly, so I could live with a workaround. But destroying all dataTables with the function in my initial post doesnt work either..

    Is there a way to reset dataTables somehow and just remove all initialised tables? It may not be optimal, performant or a beautiful solution, but it would work for me :-)

    Or, a way to check if the table is initialised and then just not do it again... Working with $('#myTable').dataTable(); to retrieve the dt-object by the node-id doesnt work either:

    $('#myTable').dataTable().destroy();
    

    throws: dataTable().destroy() is not a function.

    Thanks for suggestions
    Marcus

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin

    throws: dataTable().destroy() is not a function.

    It would, You would need to use:

    $('#myTable').DataTable().destroy();
    

    Note the capital D.

    I've tried it with destroy as well: http://live.datatables.net/muzicosa/3/edit but it seems to work okay there.

    I'm afraid that without being able to see the error I don't know what is causing it so I can't really suggest a way to workaround it or to fix properly.

    Allan

  • proggy123proggy123 Posts: 4Questions: 1Answers: 0

    Okay, so adding

    $('#table').DataTable().destroy();
    

    right before initialising every datatable does not fix it either... That is very weird, isn't it? How can it say the table is already initialised when I destroyed it right before?

    Well, as this issue is really breaking my whole project apart, if you are willing, I would like to give you access to the site for you to see the error happening. Is there a way I can send you a personal message with the URL and login-data? Like when I click on your username and then on "messsage", will that one be just for your eyes only? The project is to be kept a secret until its finalised :-)

    Thank you so much for your support!
    Marcus

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin

    HI Marus,

    I agree - it is odd. You can send me a PM by clicking my name above and then the "Send message" button.

    Allan

  • proggy123proggy123 Posts: 4Questions: 1Answers: 0

    Hi Allan,

    I asked my brother to generate some login data for you. I hope he sent it to you by now via PM.
    Let me know if anything in the code is unclear to you.

    Have a nice weekend
    Marcus

This discussion has been closed.