简体   繁体   中英

Datatable extend excel option doesn't work with pagination

In the reference here , I have the datatable with excel export customization to print with cell colors. It works fine when the paging: false, . With paging,export excel with cell color is incomplete. How to make it work with paging?

Solved by this using var colour = $(table.cell(':eq('+count+')',2).node()).css('background-color');instead of

var colour = $('tbody tr:eq('+parseInt(count)+') td:eq(2)').css('background-color');

reference here

upon building the excel, I noticed that you used to color cells in excel file by checking the css attribute color that if it's color is red you will color it in excel red also.

It works all well with your paging:false because all the cells that needs color has already been colored since all of it is displayed in one page while if your paging:true , the cells that has color in excel are only those cells that has been displayed in front page and has already been filled with color, and those that needs color that was not displayed or in other page number does not have color in excel, because it was not displayed in front and is not being colored.

so my solution for that is that to have the same condition from rowCallback inside the customized function in creating excel. please see below:

$('row c[r^="C"]', sheet).each( function (data, info) {
          console.log(info.textContent); 
          if (skippedHeader) {



            var txt = info.textContent; 
            if (txt === 'London') {
              $(this).attr( 's', '35' );
            }
            else if (txt === 'New York') {
              $(this).attr( 's', '40' );
            }

            count++;
          }
          else {
            skippedHeader = true;
          }
        });

you may also check the link: http://live.datatables.net/jijumeji/105/edit

You have to use manual render for excel and pdf export.

I think, automatic render useless.

https://editor.datatables.net/examples/extensions/exportButtons

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM