Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81687

Using TableTools to download large dataset

$
0
0
EDIT: Nevermind, I'm sure it's because it's using $_GET and exceeding the maximum number of characters that can be passed. I'll convert it to the POST version and report back.

EDIT EDIT: I used the POST version, and it's working great, even when downloading 27000+ rows with 20+ columns. Basically, I just passed the $.param(oParams) data using POST (var aoPost = [{"data": $.param(oParams)}];), and then on the processing side, I did the follwing:


if($_POST['data'])
{
	$_GET = $_POST['data'];
	parse_str($_GET);
}


I converted them to $_GET because I use the same script to generate the .csv file as I do the JSON for the server side processing, since the way it generates them is virtually the same.

-----------------------------------------------------------------------------

I'm trying to use the download GET plugin for TableTools, and am having a little trouble getting it to work. I have the following set in my document load portion:

			oTable = $('#claimTable').dataTable({
				"bProcessing": true,
				"bStateSave":true,
				"fnDrawCallback": function ( oSettings ) {

					applyEditableText($('.editable_text'));
					applyEditableSelect($('.editable_select'));
					applyEditableDate($('.editable_date'));

					if($('input[name="claim_id[]"]').length > 0)
					{
						$('.select_all').removeAttr('disabled');
						$('.deselect_all').removeAttr('disabled');
					}
					else
					{
						$('.select_all').attr('disabled', 'disabled');
						$('.deselect_all').attr('disabled', 'disabled');
					}

					get_checked_count();

					$('input[name="claim_id[]"]').click(function(){

						get_checked_count();
					});
				},
				"fnInitComplete": function(){

					var oSettings = this.fnSettings();

					$('tfoot input:visible').each(function(){

						var index = $("tfoot input").index(this);

						$(this).val(oSettings.aoPreSearchCols[index].sSearch);

						if(this.value == "")
						{
							this.className = "search_init";
							this.value = asInitVals[$("tfoot input").index(this)];
						}
					});
				},
				"aoColumnDefs": [
					{ "bSortable": false, "aTargets": [ 0 ] },
					{ "sSortDataType": "dom-text", "aTargets": [ '_all' ] }
				],
				"bServerSide": true,
				"sAjaxSource": "/members/get_claim_data.php",
				"sDom": 'T<"clear">lfrtip',
				"oTableTools": {
					"sSwfPath": "js/swf/copy_cvs_xls.swf",
					"aButtons":[{
						"sExtends": "download",
						"sButtonText": "Download CSV",
						"sUrl": "/members/get_claim_data.php?type=csv"
					}]
				},
				"bFilter":true,
				"bPaginate":true,
				"aLengthMenu": [[50, 100, 200, 500, 1000], [50, 100, 200, 500, 1000]],
				"iDisplayLength":50
			});

And the following as my plugin code:


		TableTools.BUTTONS.download = {
			"sAction": "text",
				"sTag": "default",
				"sFieldBoundary": "",
				"sFieldSeperator": "\t",
				"sNewLine": "<br>",
				"sToolTip": "",
				"sButtonClass": "DTTT_button_text",
				"sButtonClassHover": "DTTT_button_text_hover",
				"sButtonText": "Download",
				"mColumns": "all",
				"bHeader": true,
				"bFooter": true,
				"sDiv": "",
				"fnMouseover": null,
				"fnMouseout": null,
				"fnClick": function(nButton, oConfig) {

					var oParams = this.s.dt.oApi._fnAjaxParameters(this.s.dt);
					var iframe = document.createElement('iframe');
					iframe.style.height = "0px";
					iframe.style.width = "0px";
					iframe.src = oConfig.sUrl+"&"+$.param(oParams);
					document.body.appendChild(iframe);
				},
				"fnSelect": null,
				"fnComplete": null,
				"fnInit": null
			};

My question is, what should my server side script be doing? Should I be formatting the csv file and displaying the header information? If so, what is the purpose of setting the delimiter and new line options in the plugin? I have the following for my .php file:


	$size = (function_exists('mb_strlen') ? mb_strlen($output, '8bit') : strlen($output));

	header('Content-Disposition: attachment; filename=report.csv');
	header('Content-Transfer-Encoding: binary');
	header('Content-type: text/x-csv');
	header('Content-Length: ' . $size);

	echo $output;

$output is an already formatted tab delimited string, ready to be downloaded. Should I instead be returning a JSON object or something? When I click on "Download CSV" right now, it redirects the page displaying the DataTable to the .csv processing page and says it's unable to display the page. What am I missing?

Viewing all articles
Browse latest Browse all 81687

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>