Front/JS & jQuery

[jQuery][datatables] footerCallback - colspan

오선지♬ 2022. 6. 10. 18:40
728x90
반응형
,"footerCallback" : function ( row, data, start, end, display ) {
                       var api = this.api();
                       var numFormat = $.fn.dataTable.render.number(',').display;
                       
                       for(i=3; i<9; i++){
                        total = api.column( i, {page:'current'} ).data().sum();
                       
                        if(i<7){
                        $( api.column( (i-minus) ).footer() ).html(numFormat(total));
                       }else{
                        $( api.column( (i-minus) ).footer() ).html(numFormat(total)).append('%');}
                       }
                       

                       $( api.column( 0 ).footer() ).html('합계').attr('colspan', colspan);
                       $( api.column( 1 ).footer() ).addClass('txr');
                       $( api.column( 2 ).footer() ).addClass('txr');

       }


                       $( api.column( 0 ).footer() ).html('합계').attr('colspan', colspan);

 

➕ 알아야할 것은 datatables에서 colsapan으로 합쳐진 cell은 2개가 합쳐졌든 3개가 합쳐졌든 1개의 cell로 인지한다.

그래서 내가 0번째 cell에 colspan속성을 부여했는데 3개의 cell 을 합친것이였다.

tobody로 봤을 때는 index가 3인 (4번째 cell)이 footer에서는 index가 1 (2번째)이다.

그래서 설정하는데 머리가 복잡했었다.

colspan기능 좀 넣어주지요....ㅎㅎㅎㅎㅎ 

728x90
반응형