How to export selected rows in special order?

How to export selected rows in special order?

ck1987deck1987de Posts: 1Questions: 1Answers: 0

Hi,

I'm using datatables 1.9.4 with tabletools and colvis plug-ins. It works nice but if I sort my table by another column and want to export only a few selected rows the initial order is used. When I export all rows the current order is used as expected.

Here is the code for my customized XLS button:

TableTools.BUTTONS.downloadXLS = {
    "sAction": "text",
    "sTag": "default",
    "sFieldBoundary": "",
    "sFieldSeperator": "\t",
    "sNewLine": "<br>",
    "sToolTip": "",
    "sButtonClass": "DTTT_button_text",
    "sButtonClassHover": "DTTT_button_text_hover",
    "sButtonText": "Download",
    "mColumns": "all",
    "bHeader": true,
    "bFooter": true,
    "sDiv": "",
    "fnMouseover": null,
    "fnMouseout": null,
    "fnClick": function( nButton, oConfig ) {
        var aoPost = this.fnGetTableData(oConfig);

        var dataInput = document.createElement("input") ;
        dataInput.setAttribute("name", "data") ;
        dataInput.setAttribute("value", aoPost);
        dataInput.setAttribute("type", "hidden");
        
        var nameInput = document.createElement("input") ;
        nameInput.setAttribute("name", 'name') ;
        nameInput.setAttribute("value", oConfig.sTitle);
        
        var myForm = document.createElement("form");
        myForm.method = 'post';
        myForm.action = 'scripts/' + oConfig.sUrl;
        myForm.appendChild(dataInput);
        myForm.appendChild(nameInput);
        
        document.body.appendChild(myForm) ;
        myForm.submit() ;
        document.body.removeChild(myForm) ;
    },
    "fnSelect": null,
    "fnComplete": null,
    "fnInit": null
};

Here is the code for the tabletools instance:

if (document.getElementById('exportSelectedRows').checked) {
                newTableTools = new TableTools($('#datatable').dataTable(), {
                    "aButtons": [{
                        "sExtends": "downloadXLS",
                        "sTitle": 'foo.xls',
                        "sButtonText": "Save as XLS",
                        "mColumns": "visible",
                        "bSelectedOnly": "true",
                        "sUrl": "../php/save_as_xls.php",
                        "oSelectorOpts": {
                order: 'current'
            }
                    }, ],
                    'sRowSelect': 'multi',
                });
            } else {
                newTableTools = new TableTools($('#datatable').dataTable(), {
                    "aButtons": [{
                        "sExtends": "downloadXLS",
                        "sTitle": 'foo.xls',
                        "sButtonText": "Save as XLS",
                        "mColumns": "visible",
                        "sUrl": "../php/save_as_xls.php",
                        "oSelectorOpts": {
                order: 'current'
            }
                    }, ],
                    'sRowSelect': 'multi',
                });
            }

Thank you!

This discussion has been closed.