Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery dataTables - TableTools not working

I'm using http://datatables.net/extensions/tabletools/ in my local-host ( wamp server ). It's working fine, but when I put the same code on my online server, it isn't working.

I am using all latest version of datatables

tableTools: {
    "sSwfPath": "https://datatables.net/release-datatables/extensions/TableTools/swf/copy_csv_xls_pdf.swf",
    "sRowSelect": "os",
    "sRowSelector": 'td:first-child',
    // "aButtons": [ "copy", "csv", "xls","pdf","print","select_all", "select_none" ]
    "aButtons": [
        "copy",
        "print", {
            "sExtends": "collection",
            "sButtonText": "Save", // button name 
            // "aButtons":    [ "csv", "xls", "pdf" ]
            "aButtons": [
                "csv",
                "xls", {
                    "sExtends": "pdf",
                    "sPdfOrientation": "landscape",
                    "sPdfMessage": "List of product."
                },
                "print"
            ]
        }
    ]
}    

Firstly there was no click on copy, pdf, csv, xls button. Hence I taught my path or swf is not working hence I replaced the link with online link. Hence now I get click, but when I click Copy button it gives me a message ... but when I past in my notepad it's giving me "blank ". Also my pdf, csv, xlsx is not working. Only Print is working perfect. Please let me know what is the issue as in my localhost all is working fine. Its creating issues in my online server.

like image 560
user3209031 Avatar asked Jul 19 '14 06:07

user3209031


1 Answers

I meant you should post it as a completely new question, since it in fact is a new question! :) Anyway. The problem is, that you'll need to render the data, when you produce a PDF. Otherwise you will just get some $(element).text() output, including the select and its options. Like this :

 "aButtons": [ 
      "copy", 
      "csv", 
      "xls",
      { "sExtends":  "pdf",
        "fnCellRender": function ( sValue, iColumn, nTr, iDataIndex ) {
           //extract the value of the select  
           if ( iColumn === 7 ) {
              var val=$(sValue).find('select').val(); 
              return (val!=='') ? val : 'not set';
           }
           //create a dummy text for the HTML-link
           if ( iColumn === 8 ) {
              return 'click';
           }
           return sValue;
         }
      },
      "print",
      "select_all", 
      "select_none" 
  ]

see your code here (as close I can get) -> http://jsfiddle.net/3F8ZJ/. However, you still have a problem caused by your mRender rendering, so the column positions is messing up. It breaks the internal <table>-structure. Why are you inserting extra <td>..</td>? But have not time to look into this at the moment.

like image 94
davidkonrad Avatar answered Nov 12 '22 21:11

davidkonrad