Can footerCallback get an on/off button?

Can footerCallback get an on/off button?

cha59cha59 Posts: 87Questions: 23Answers: 0
edited February 2023 in DataTables

My datatable has a DOM size of 40.866, so it's gettiing a bit slow with inline editing. Is it possible to have a button that turnes off footerCallback while putting data in, and then turn footerCallback on again?

    "footerCallback": function ( row, data, start, end, display ) {// summerer pr. uge i bunden
            var api = this.api(), data;
            //liste med column nr., der skal loopes igennem
            colList = [10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,
            37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59];
            for (i=0; i < colList.length; i++) {//i nulstilles, men næste linje starter ved column 5
                var index = colList[i];//her skifter den column
                
                // Sum af hver uge
                pageTotal = api
                .column( index, { page: 'current'} )//index bruges her i stedet for column nr
                .data()
                .reduce( function (a, b) {
                return intVal(a) + intVal(b);
                 }, 0 );
     
                // Update footer
                $( api.column( index ).footer() ).html(//index bruges her i stedet for column nr
                    pageTotal
                );
            
            }//lukker loopen med index
                // sum af kolonne 10, fordelt i alt. Bygger på sum af hver uge, så skal komme efter
                data = api.column( 10, { page: 'current'} ).cache('search');
                total = data.length ?//i virkeligheden en hvis sætning, ? = hvis
                data.reduce( function (a, b) {
                        return intVal(a) + intVal(b);
                 }, 0 ): 0;

  
                // Update footer på kolonne 10 (må ikke være en fixed column, så virker det ikke)
                //numFormat formaterer tal med tusindtalseperator
                var numFormat = $.fn.dataTable.render.number( '.', ',',0).display;
                $( api.column( 10 ).footer() ).html(
                numFormat(total)
                );

                // sum af kolonne 9, Lektioner. Bygger på sum af hver uge, så skal komme efter
                data = api.column( 9, { page: 'current'} ).cache('search');
                total = data.length ?//i virkeligheden en hvis sætning, ? = hvis
                data.reduce( function (a, b) {
                        return intVal(a) + intVal(b);
                 }, 0 ): 0;

  
                // Update footer på kolonne 9 (må ikke være en fixed column, så virker det ikke)
                $( api.column( 9 ).footer() ).html(
                numFormat(total)
                );
            
                //sum af kolonne 7, timer i alt. 
                data = api.column( 7, { page: 'current'} ).cache('search');
                total = data.length ?//i virkeligheden en hvis sætning, ? = hvis
                data.reduce( function (a, b) {
                        return intVal(a) + intVal(b);
                 }, 0 ): 0;

                // Update footer på kolonne 7 (må ikke være en fixed column, så virker det ikke)
                $( api.column( 7 ).footer() ).html(
                numFormat(total)
                );
        }  //lukker footerCallback

mvh cha59

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    Answer ✓

    There is not an option to turn off and on the footerCallback. You could set a flag (global variable maybe) and check that flag in the footerCallback to decide if the code should be executed.

    Kevin

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    Answer ✓

    Another option might be to use a global variable to keep track of which columns to updated based on the table changes. Instead of setting colList to all the columns just set it to the changed columns. When you inline edit a cell update the colList to include only the column for that cell.

    See this example for getting the column index of the inline edited cell.
    https://live.datatables.net/guwafemu/351/edit

    Kevin

  • cha59cha59 Posts: 87Questions: 23Answers: 0

    Thanks Kevin - I'm working on your latter proposal.
    Claus

Sign In or Register to comment.