Save rows selected bSelectedOnly or all when no selected

Save rows selected bSelectedOnly or all when no selected

bandit88bandit88 Posts: 2Questions: 0Answers: 0
edited May 2011 in General
Hello,

I use datatables and it's great. I would like use bSelectedOnly: true to save files (like by default) but i would like it saves all data if no rows are selected.

If someone can help me, thanks

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    What you could do is customise the fnClick function for that button ( http://datatables.net/extras/tabletools/button_options#fnClick ) and modify the bSelectedOnly property of the object just before calling fnGetTableData, based on the number of rows selected (which you can get from the API TableTools presents).

    Allan
  • ctct Posts: 9Questions: 0Answers: 0
    Hi Allan,

    I tried this and it didn't work.


    {
    "sExtends": "copy",
    "fnClick": function ( nButton, oConfig, oFlash ) {
    oConfig['bSelectedOnly'] = false;
    }
    },

    which should always set the bSelectedOnly to false, but when I click on the button it will say "1 row copied"

    Please help!
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    The '1 row copied' is probably a different issue since you aren't actually sending any data to Flash - so likely it has copied only a new line character to the clipboard - hence the 1 line alert.

    Rather than overriding fnClick, I'd suggest just using bSelectedOnly like in this code example: http://datatables.net/extras/tabletools/button_options#bSelectedOnly

    The documentation for bSelectedOnly says "If no rows are selected, then all data is used." - which is exactly what you want (so my original suggestion was a little over the top - sorry).

    Allan
  • ctct Posts: 9Questions: 0Answers: 0
    edited July 2011
    Hi Allan,

    That was my first option but it didn't work. It just says copied 0 rows to clipboard.

    [code]
    "oTableTools": {
    "sSwfPath": "/media/swf/dataTables.copy_cvs_xls_pdf.swf",
    "sRowSelect": "multi",
    "aButtons": [
    {
    "sExtends": "select_all",
    "sButtonText": "Select All"
    },
    {
    "sExtends": "select_none",
    "sButtonText": "Select None"
    },
    {
    "sExtends": "copy",
    "bSelectedOnly": true
    },
    {
    "sExtends": "collection",
    "sButtonText": "Export",
    "aButtons": [ {
    "sExtends": "csv",
    "bSelectedOnly": true
    },
    {
    "sExtends": "xls",
    "bSelectedOnly": true
    },
    {
    "sExtends": "pdf",
    "sPdfOrientation": "landscape",
    "bSelectedOnly": true
    }]
    },
    {
    "sExtends": "print"
    }
    ]
    },
    [/code]
    When I take away the "bSelectedOnly": true, it copies corectly.
  • ctct Posts: 9Questions: 0Answers: 0
    Also copying selected rows do work correctly, only the "no selection" copy/csv/etc doesn't work.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    I'll try it out on my own machine when I get back to it (remote atm). If you could post a link to the example you are using, that would be useful.

    Thanks,
    Allan
  • ctct Posts: 9Questions: 0Answers: 0
    Hi Allan,

    Unfortunately I can't provide a link sorry. :-S

    Thanks
  • jurikobejurikobe Posts: 7Questions: 0Answers: 0
    I got the same problem now..
This discussion has been closed.