Export selected rows only to excel

Export selected rows only to excel

aliBaliB Posts: 6Questions: 0Answers: 0
edited March 2014 in TableTools
Hi,

I created two button, one to download the entire list in excel and one to download only the visible list

"aButtons": [
{
"sExtends": "xls",
"sFileName": "projectsList.xls",
"sButtonText": "Download All To Excel"
},
{
"sExtends": "xls",
"sFileName": "visibleProjectList.xls",
"sButtonText": "Download Visible List To Excel",
"bSelectedOnly": true,
"fnClick": function ( nButton, oConfig, oFlash ) {
this.fnSelect( $('tbody tr') );
this.fnSetText(oFlash, this.fnGetTableData(oConfig));
}
}
]
},

The download all to excel is working fine, but when i click download visible list it the generated excel rows are not the same one that are selected. By default they are sorted by IDs, when I download the full list, it is fine and sorted by IDs but when I download visible list the excel sheets contains 50 rows sorted by name(iDisplayLength is 50)

Thanks

Replies

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin
    Use the bSelectedOnly option: http://datatables.net/extras/tabletools/button_options#bSelectedOnly if you want to export only the selected rows.

    Allan
  • aliBaliB Posts: 6Questions: 0Answers: 0
    bSelectedOnly is already set to true

    This is the full initialization

    oTable = jQuery("#projects-table").dataTable({
    "oLanguage": {
    "sEmptyTable": "No Data Found"
    },
    "bPaginate": true,
    "bLengthChange": true,
    "iDisplayLength": 50,
    "bInfo": true,
    "sPaginationType": "full_numbers",
    "bFilter": true,
    "sDom": 'T<"clear">frtlip',
    "oTableTools": {
    "sSwfPath": "/media/swf/copy_csv_xls_pdf.swf",
    "sRowSelect": "multi",
    "aButtons": [
    {
    "sExtends": "xls",
    "sFileName": "projectsList.xls",
    "sButtonText": "Download All To Excel"
    },
    {
    "sExtends": "xls",
    "sFileName": "visibleProjectList.xls",
    "sButtonText": "Download Visible List To Excel",
    "bSelectedOnly": true,
    "fnClick": function ( nButton, oConfig, oFlash ) {
    this.fnSelect( $('tbody tr') );
    this.fnSetText(oFlash, this.fnGetTableData(oConfig));
    }
    }
    ]
    },
    "bSort": true,

    });
  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin
    Can you please link to a test case showing the problem so I can debug it. As far as I can see locally, it does indeed work as expected.

    Allan
  • aliBaliB Posts: 6Questions: 0Answers: 0
    http://live.datatables.net/gitivaf/1/edit

    please only modify the sSwfPath in JS to make the download work

    thanks
  • aliBaliB Posts: 6Questions: 0Answers: 0
    Also i would appreciate help on the date range filters

    Thanks
This discussion has been closed.