Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery - DataTables [tableTools]: export only visible rows

I just started out using jQuery DataTables.

using the tableTools of DataTables, is it possible to only export visible rows instead of all the rows? If for example the pagination was set to 10 I would expect only 10 rows to be exported. The same goes for a search result.

Here's part of the code:

$(document).ready(function() {
      var table = $('#example').DataTable({
        "pagingType": "full_numbers",
          "iDisplayLength" : 10,
                dom: 'T<"clear">lfrtip',
                 "oTableTools": {
            "aButtons": [
{ "sExtends": "copy", "mColumns": "visible",      "bSelectedOnly": true },
{ "sExtends": "xls", "mColumns": "visible" },
{ "sExtends": "print", "mColumns": "visible" }

], "sRowSelect": "multi"},


             "order": [[ 0, "asc" ]]
    } ) ;...

Thank you.

like image 659
Tony Clifton Avatar asked May 28 '14 12:05

Tony Clifton


2 Answers

I used this solution and it worked. Try this:

<script>
$(document).ready(function() {
    var table = $('#example').DataTable( {
        "pagingType": "full_numbers",
        "iDisplayLength": 10,
        "dom": 'T<"clear">lfrtip',
        "oTableTools": {
          "aButtons": [
            {'sExtends':'copy',
              "oSelectorOpts": { filter: 'applied', order: 'current' },
            },
            {'sExtends':'xls',
              "oSelectorOpts": { filter: 'applied', order: 'current' },
            },
            {'sExtends':'print',
              "oSelectorOpts": { filter: 'applied', order: 'current' },
            }
          ]
        },
    });
});
</script>
like image 73
saghar.fadaei Avatar answered Oct 11 '22 22:10

saghar.fadaei


You may set the selection of the page to current page for specific export.

Ref: http://datatables.net/docs/DataTables/1.9.4/#$

{ "sExtends": "xls", "mColumns": "visible", "oSelectorOpts": { page: "current" } }
like image 33
StartingFromScratch Avatar answered Oct 11 '22 23:10

StartingFromScratch