Cancel print when no rows are selected

Cancel print when no rows are selected

winonageekwinonageek Posts: 4Questions: 0Answers: 0
edited March 2012 in TableTools
I'm attempting to extend the ajax button and print only selected rows from the DataTable.
[code]
"oTableTools": {
"sSwfPath": "@Url.Content("~/Content/swf/copy_cvs_xls.swf")",
"sRowSelect": "multi",
"aButtons": [{
"sExtends": "ajax",
"sAction": "print",
"sInfo": "",
"sMessage": "Your selected records are ready to be printed. Use your browser's print function to print this information. " +
"Press escape when finished. These instructions will not be printed.",
"sButtonText": "Print Selected Rows",
"sButtonClass": "DTTT_button_print",
"sButtonClassHover": "DTTT_button_print_hover",
"bSelectedOnly": "true",
"sAjaxUrl": "PrintSelected.aspx",
"mColumns": [ 0 ],
"sFieldSeperator": "_&_",
"fnClick": function(nButton, oConfig, oFlash) {
var sData = this.fnGetSelectedData();

// check if any rows were selected
if (length in sData) {
alert("We got one!");

$.ajax({
"url": oConfig.sAjaxUrl,
"data": [{ "name": "tableData", "value": buildArray(sData) }],
"success": function(results) {
$('#wsu-print-table div#wsu-print-data').text(results); // populate the data
},
"dataType": "json",
"type": "POST",
"cache": false,
"error": function(){
alert("Error during print call.");
}
});
} else {
alert("Nothing found");
// stop and don't show print page
}
}
}]
}
[/code]

What I'm encountering is that regardless of the [code]if (length in sData)[/code] check (true or false), the print function always runs and the page is decorated and rendered for printing. When the check is false, how do I tell TableTools to not render the page for printing because no rows were selected?

Replies

This discussion has been closed.