fnDrawCallback questions
fnDrawCallback questions
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.
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.
This discussion has been closed.
Replies
[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]
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...
Allan