Download selected rows across non-visible pages, or trigger clearing of search box on download?

Download selected rows across non-visible pages, or trigger clearing of search box on download?

crash85crash85 Posts: 48Questions: 5Answers: 0

You guys have been lifesavers helping with this code! It's pretty much been entirely written by users of this forum, I am ever grateful..... AND I bring you another question. XD

I have a download button that will either download the entire table if nothing is selected, or just the selected row. It works great....EXCEPT if you use the search box to filter the table. Then if you try to download any selected rows, it will only download the ones currently visible on the filtered page.

{
        extend: 'csv',
        fieldBoundary: '',
        text: '<span class="fa fa-file-excel-o"></span> Download (ALL) or (SELECTED)',
        exportOptions: {
          columns: [6, 3],
          modifier: {
            search: 'applied',
            order: 'applied'
          }
        }
      }

Is there a way to make this button download any of the selected items on the non-visible portion as well? OR is there a way to clear the search field when you click the download button in order to re-draw all the selected rows together for download. (Currently if you select rows from the main page, and then from filtered pages, the table will aggregate all of them together once you clear the search box.)

Fiddle: http://jsfiddle.net/crashvector/pzLm8ead/11/

Answers

  • crash85crash85 Posts: 48Questions: 5Answers: 0

    Maybe something like:

    $('#example').DataTable().search('').draw();
    

    But not sure how that fits into the csv button.

  • crash85crash85 Posts: 48Questions: 5Answers: 0
    edited April 2019

    Nevermind, that was a lot simpler than I thought. Had a moment to sit down and look through examples and found the search modifier for the csv export. I changed "applied" to "none".

    Although, I would be interested to know if you can clear the search and have other actions when clicking the button. ( I attempted to add an action line and call a function, but it wouldn't work.)

    Something like: http://jsfiddle.net/crashvector/pzLm8ead/18/

          {
            extend: 'csv',
            fieldBoundary: '',
            action: function (dt) {
              testDraw (dt);
            },
            text: '<span class="fa fa-file-excel-o"></span> Download (ALL) or (SELECTED)',
            exportOptions: {
              columns: [6, 3],
              modifier: {
                search: 'none',
                order: 'applied'
              }
            }
          }
        ]
      });
      
      //testing to see if search bar can be cleared, commit dropdows, and draw table
      function testDraw(dt){
        $('#samples').DataTable().search('').draw();
        if($(row.node()).find('select').length){
              writeCell($(row.node()).find('select'));
            }
            toggleDataAndDraw(row, type, 0);
        dataTable.draw();
        
      }
    

    Looks like this might get me in the right direction?
    https://datatables.net/forums/discussion/33209/run-script-before-exporting-begins-buttons-plugin

This discussion has been closed.