Last active
September 28, 2017 01:38
-
-
Save TheSin-/ce24a9b551ae3ebd8f4828bae7ea572d to your computer and use it in GitHub Desktop.
How to get all results via output callback with TableSorter and Ajax pager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output_callback : function(c, data, url) { | |
var filename = $('#A3opts .output-filename').val(); | |
var newURL = url.replace(/page=[0-9]+/, 'page=0').replace(/size=[0-9]+/, 'size=10000000'); | |
if (c.originalSettings.widgetOptions.output_saveFileName == 'dynamic') | |
filename = $('" . $this->table . "').find('caption').text().replace(/\s/g, '_') + '.csv'; | |
$('#csvForm #filename', top.$('#toolbar').contents()).val(filename); | |
// remove filters for all rows | |
if (c.widgetOptions.output_saveRows == 'a') | |
newURL = newURL.replace(/&fcol(\[[0-9]+\])?=.+/g, '') + '&fcol'; | |
$.ajax({ | |
url: newURL | |
}).done(function(data) { | |
if (!data) { | |
alert('Request had too much data, try to filter out some results and only export visible rows'); | |
console.log('Ajax must have timed out, results too large!'); | |
return false; | |
} | |
try { | |
data = $.parseJSON(data); | |
} catch(e) { | |
alert('Something went wrong!'); | |
console.log('Ajax did not return proper JSON'); | |
console.log(e); | |
return false; | |
} | |
var rows = c.widgetOptions.pager_ajaxProcessing(data, c.table); | |
data = $.tablesorter.output.process(c, c.widgetOptions, rows['rows'], true); | |
$('#csvForm #data', top.$('#toolbar').contents()).val(data); | |
setTimeout(function() { | |
$('#csvForm', top.$('#toolbar').contents()).submit(); | |
setTimeout(function() { | |
$('#csvForm #filename', top.$('#toolbar').contents()).val(''); | |
$('#csvForm #data', top.$('#toolbar').contents()).val(''); | |
}, 250); | |
}, 250); | |
}); | |
} else { | |
$('#csvForm #data', top.$('#toolbar').contents()).val(data); | |
setTimeout(function() { | |
$('#csvForm', top.$('#toolbar').contents()).submit(); | |
setTimeout(function() { | |
$('#csvForm #filename', top.$('#toolbar').contents()).val(''); | |
$('#csvForm #data', top.$('#toolbar').contents()).val(''); | |
}, 250); | |
}, 250); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment