Loop of footer callback

Loop of footer callback

cha59cha59 Posts: 87Questions: 23Answers: 0

Does anyone have an idea of how to loop the footer callback. I'm about to have 40 columns, so it would be nice to loop through this code instead of making code for each column. Example for columns 8 to 10

        // Total over this page
        pageTotal = api
            .column( 8, { page: 'current'} )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            }, 0 );

        // Update footer
        $( api.column( 8 ).footer() ).html(
            pageTotal
        );

        // Total over this page
        pageTotal = api
            .column( 9, { page: 'current'} )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            }, 0 );

        // Update footer
        $( api.column( 9 ).footer() ).html(
            pageTotal
        );

        // Total over this page
        pageTotal = api
            .column( 10, { page: 'current'} )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            }, 0 );

        // Update footer
        $( api.column( 10 ).footer() ).html(
            pageTotal
        );

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,448Questions: 26Answers: 4,974
    Answer ✓

    You can use a simple for loop. Maybe something like this:

      colList = [8, 9, 10];
      
      for (i=0; i < colList.length; i++) {
        var index = colList[i];
    
        // Total over this page
        pageTotal = api
            .column( index, { page: 'current'} )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            }, 0 );
     
        // Update footer
        $( api.column( index ).footer() ).html(
            pageTotal
        );
      }
    

    Didn't try it but it seems like it would work

    Kevin

  • cha59cha59 Posts: 87Questions: 23Answers: 0

    Thanks a lot Kevin, it works!
    Claus

This discussion has been closed.