Destroy/ReCreate Datatable with footercallback

Destroy/ReCreate Datatable with footercallback

GoddardGoddard Posts: 14Questions: 6Answers: 0

I have a datatable where I dynamically create the headers. It works great.

On first load all my data is loaded from the server using the "ajax" option on data table.

I have additional filters that "recreate" the datatable and pulls in new headers.

A problem I am having is when I recreate my datatable I destroy the old and empty part of the data table. One thing I have been having to do is if I have a footer, I need to NOT clear the entire #data-table. I have to clear only the scrollheader.

For example at the top of my creation javascript function.
if ($.fn.DataTable.isDataTable('#report-table')) {
$('#report-table').DataTable().destroy();
$('#report-table .dataTables_scrollHead').empty();
<?php if($footer == false) { echo "$('#report-table').empty();"; } ?>
}

I don't know if I am destroying wrong, or creating the footer wrong, or what. Eventually I want dynamic headers, body, and footer. So right now everything is working with this $footer == false that comes from my server. Doing this allows everything to function normally, but it seems very hacky and I was wondering what is the proper way and will allow me to have dynamic footers.

Thanks

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • GoddardGoddard Posts: 14Questions: 6Answers: 0

    I'm not really looking for you to help debug my code.

    I am asking how do you handle dynamic footers and how do you manage destruction and recreation properly.

    Thank you

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    Maybe you can replace

    $('#report-table .dataTables_scrollHead').empty();
    <?php if($footer == false) { echo "$('#report-table').empty();"; } ?>
    

    with

    $('#report-table').empty();
    

    Like this example:
    http://live.datatables.net/huyexejo/260/edit

    Kevin

  • GoddardGoddard Posts: 14Questions: 6Answers: 0

    Thanks I will look at your example.

This discussion has been closed.