fnDrawCallback questions

fnDrawCallback questions

susangsusang Posts: 5Questions: 0Answers: 0
edited August 2011 in General
I've inherited a web report that uses DataTables with ColdFusion 8 to display its data. I need to set up some export functions for Excel and PDF. Normally, this would be easy to do in ColdFusion via a cfcontent tag, but I want to be able to pass the current sorting and filtering information to the export so the excel/pdf file will look identical to the data the user has currently displayed. My predecessor was using DataTables 1.7.4 but I've downloaded the latest version (1.8.1).

In poking around this site, fnDrawCallback jumped out as the probable mechanic I want to use. However, I'm having trouble getting it to work. Can someone help me out?

Here's what I currently have (this works):

[code]

$(document).ready(function() {
oTable = $('#xget').dataTable({
"oLanguage": { "sSearch": "Type anything to filter this data:" },
"iDisplayLength": 25,
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
});

[/code]

Based on the fnDrawCallback example from the website, I tried to modify it so:

[code]

$(document).ready(function() {
oTable = $('#xget').dataTable({
"fnDrawCallback": function() {
alert('foo');
}
"oLanguage": { "sSearch": "Type anything to filter this data:" },
"iDisplayLength": 25,
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
});

[/code]

This however causes all of the DataTables functions to break. It doesn't throw an error, and the base table still displays, but the pagination/filtering options don't appear, and clicking on the column headers no longer sorts.

So there's problem #1.

Issue 2 is that I need fnDrawCallback to actually return the current pagination/sorting/filtering variables (ie if I'm filtering on the word "jeep" and want to sort by user's last name, I need to know that) so that I can pass that info along to ColdFusion, so that it can handle the export. What arguments will I need to pass in order to get that info?

Obviously I'm a DataTables newbie. I would really appreciate it if anyone can help walk me through this.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    you're missing the comma after the function on line 06
    [code]


    $(document).ready(function() {
    oTable = $('#xget').dataTable({
    "fnDrawCallback": function() {
    alert('foo');
    }
    , // <---- missing
    "oLanguage": { "sSearch": "Type anything to filter this data:" },
    "iDisplayLength": 25,
    "bJQueryUI": true,
    "sPaginationType": "full_numbers"
    });
    });


    [/code]
  • susangsusang Posts: 5Questions: 0Answers: 0
    *facepalm*

    I can't believe I missed that. Ok, issue 1 solved.

    Now I'm left with getting a sorted, filtered table that I can export to excel/pdf. I was thinking of just grabbing the outerHTML of oTable and dumping that into the cfcontent tag, but there must be a more elegant way...
  • allanallan Posts: 63,243Questions: 1Answers: 10,419 Site admin
    How about TableTools: http://datatables.net/extras/tabletools/ :-) If you wanted to use server-side file generation rather than client-side, you could use a plug-in for TableTools such as the download one: http://datatables.net/extras/tabletools/plug-ins#download

    Allan
This discussion has been closed.