Using table().container()

Using table().container()

jclopmeljclopmel Posts: 2Questions: 1Answers: 0

Hello,

I try to use Datable for first time in my code, and I can't handle the "table().container()" API function.

At first I create the datatable and I load the data from a PHP server. My problem is that I'd like to "addClass()" to the main container #products_datatable_wrapper, but I am not able, any suggestion would be quite helpful.

Here ir a summary of my js code:

var table = $('#products_datatable').DataTable( {} );
$( table.table().container()).addClass('p-0');

Thanks a lot!

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @jclopmel ,

    I tried and it seems OK for me - see this screenshot:

    Can you show us an example please of how it's failing for you?

    Cheers,

    Clin

  • jclopmeljclopmel Posts: 2Questions: 1Answers: 0
    edited April 2018

    I'd like but I can't show the real code because it's protected and I haven't privileges enough to do it. In any case, now I know it works for you, I'm sure I'm doing something wrong. I already tried the same but with "drawCallback", and it does work fine. I don't know the difference among them.

    "drawCallback": function( settings ) {
                $('#products_datatable_wrapper').addClass("p-0");
    },
    

    Thanks a lot!

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    I'm surprised table().container() doesn't work, it doesn't really do much. drawCallback is called every time the table is drawn - so after the page is changed, a sort applied, etc. Therefore, it won't be efficient, but at least you're moving!

    C

This discussion has been closed.