Caused FooterCallback to be called twice

Caused FooterCallback to be called twice

sbelladsbellad Posts: 5Questions: 3Answers: 0
edited January 2021 in FixedColumns

bug: FixedColumns causes FooterCallback to be called twice ?
http://live.datatables.net/beribipu/1/edit
see: console output (does only once if you remove fixedColumns)
"footerCallback"
"footerCallback"

Same issue with searchPanes as well.

Answers

  • kthorngrenkthorngren Posts: 21,261Questions: 26Answers: 4,934

    FixedColumns, SearchPanes and likely other extensions call the draw() API as part of their initialization. You can see this behavior in this example using the preDraw and draw events.
    http://live.datatables.net/beribipu/2/edit

    Kevin

  • sbelladsbellad Posts: 5Questions: 3Answers: 0
    edited January 2021

    Think this is a bug as I have 28 columns and 150 rows on the page that needs footer sum calculations. Since footer is called 3 times it makes it visibly slow.
    Hoped there is a defredDraw event which would use a queue to avoid multiple draws within x mills

    just for info...I am using this hack as workaround:

    var lastFooterCallback = 0;
    var delay = 200;
    $(document).ready(function() {
       dataTable = $('#example').DataTable({
            // ...
            footerCallback: function ( row, data, start, end, display ) {
                if (lastFooterCallback >= (Date.now() - delay))
                    return;
                lastFooterCallback = Date.now();
                // footer code here
    
  • kthorngrenkthorngren Posts: 21,261Questions: 26Answers: 4,934
    edited January 2021

    The footerCallback docs state this:

    Identical to headerCallback but for the table footer this function allows you to modify the table footer on every 'draw' event.

    So it is working as expected and will run any time the Datatable is drawn, ie, searches, paging, sorting and when certain extensions are initialized and need to draw the table. Maybe you can use a global variable flag to skip running the footerCallback during initialization and only run it after, for example:
    http://live.datatables.net/beribipu/3/edit

    EDIT: Added searchpanes to the example.

    Kevin

This discussion has been closed.