file exporting when filters/search made on the table contents and also colors/headers

file exporting when filters/search made on the table contents and also colors/headers

umaeswaraumaeswara Posts: 69Questions: 13Answers: 0

I see this example https://datatables.net/extensions/buttons/examples/initialisation/export.html. how to make it work when a filter is applied or search is made. after search made still it is exporting full table i would like if it can export only the results of search or filter. my table columns are filterable.

And also the table has rows in different color shades, how can we make sure the exported xlsheet also has same colors? is it possible?

thanks,
Uma-

Answers

  • colincolin Posts: 15,234Questions: 1Answers: 2,597

    By default, it will only export the filtered rows. This example from this thread shows how to export all rows.

    For colours, see this example from this thread,

    Colin

  • umaeswaraumaeswara Posts: 69Questions: 13Answers: 0

    thanks Colin, this is really helpful.

  • umaeswaraumaeswara Posts: 69Questions: 13Answers: 0
    edited January 2021

    btw, how do i insert other buttons here, like pdf,csv,copy etc.

    buttons: [{
          extend: 'excelHtml5',
          text: 'Mybutton',
          customize: function ( xlsx ) {
            var sheet = xlsx.xl.worksheets['sheet1.xml'];
            
            var count = 0;
            var skippedHeader = false;
            $('row c[r^="C"]', sheet).each( function () {
              if (skippedHeader) {
                var colour = $('tbody tr:eq('+parseInt(count)+') td:eq(2)').css('background-color');
                if (colour === 'rgb(255, 0, 0)') {
                  $(this).attr( 's', '35' );
                }
                else if (colour === 'rgb(0, 128, 0)') {
                  $(this).attr( 's', '40' );
                }
                count++;
              }
              else {
                skippedHeader = true;
              }
            });
          }
        }]
    

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

  • colincolin Posts: 15,234Questions: 1Answers: 2,597

    At a glance that looks like it should do the trick - other examples here should also help if you are having problems.

    If no joy, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • umaeswaraumaeswara Posts: 69Questions: 13Answers: 0

    thanks Colin. sure, i will add example in my future queries.
    btw, i am trying to minimizing the .js files i need to include on the webpage. i see these three are certainly needed for this excel button to be visible and work. do you agree or can I reduce it further ? i removed this jszip.min.js but then my button was not visible.
    why do we need this jszip.min.js ?


  • umaeswaraumaeswara Posts: 69Questions: 13Answers: 0

    here is the example: http://live.datatables.net/nudeyosa/1/edit
    see it doesnt show "Excel" button if I comment out jszip.min.js .
    why is that needed?

  • colincolin Posts: 15,234Questions: 1Answers: 2,597

    Oh I see, thanks for the test case. Yep, you need that file as it's used to construct the download file.

    Colin

  • umaeswaraumaeswara Posts: 69Questions: 13Answers: 0

    thanks colin, please check this testcase http://live.datatables.net/nudeyosa/1/edit
    i want user to have a choice for choosing filename for the exported, right now i am giving the default name. can you please help me, if i can give a choice to user to give a name when they are about to save?

  • kthorngrenkthorngren Posts: 21,000Questions: 26Answers: 4,889

    According to the buttons.exportInfo() docs you can set the title with a function. Maybe that will work for your case.

    Kevin

  • colincolin Posts: 15,234Questions: 1Answers: 2,597

    Yep, title as Kevin said, example here: https://datatables.net/extensions/buttons/examples/html5/filename.html

    Colin

This discussion has been closed.