使用表工具单击“打印视图”选项时,数据表服务器端处理命中数据库。
if (gridcount != null && parseInt(gridcount) > 0) {
_displayCount = parseInt(gridcount);
}
loaddatatable();
function loaddatatable()
{
_fromdate = $('#FromDateSelect').val();
_todate = $('#ToDateSelect').val();
$('#ddBankAccountYears').val($('#HBankAccountYear').val());
_Year = $('#ddBankAccountYears').val();
oTable = $('#List').dataTable({
"bStateSave": true,
"fnStateSave": function (oSettings, oData) {
$('#displayCount').val(oData.iLength);
$('#SortType').val(oData.aaSorting[0][1]);
$('#SortColumn').val(oData.aaSorting[0][0]);
},
"sDom": 'l<"floatR pL5"T><"floatR"f>rtip',
"bDestroy": true,
"aaSorting": [[_SortColumn, _sortType]],
"iDisplayLength": _displayCount,
"bServerSide": true,
"sAjaxSource": "/ControllerName/AjaxHandler?id=" + _AccountId + "&id2=" + _Year + "&fromdate=" + encodeURIComponent(_fromdate) + "&todate=" + encodeURIComponent(_todate),
"bProcessing": true,
"aoColumns": []
});
}
这里是我们使用的代码示例,当我们使用表格工具单击Datatable的“打印”视图选项时,问题就在于此。 Ajax方法正在被攻击并获取值。实际上它不应该点击它应该显示的方法或单独抓取数据并显示。
答案 0 :(得分:0)
使用TableTools扩展 2.2.4 进入类似问题
我处理以避免再次击中控制器的方法是使用 "bShowAll": false
option。
我也按using $.fn.dataTable.TableTools
初始化TableTools。
JS代码:
$(document).ready(function () {
//server side processing
var table = $('#dataTable').DataTable({
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"bPaginate": true,
"processing": true,
"serverSide": true,
"ajax": {
"url": "/app/api/class/getData",
"type": "POST",
// additional params for the method (optiona)
data: {
startDate: startDate,
endDate: endDate
}
},
"columns": [
{"data": "date"},
{"data": "name"},
{"data": "email"},
],
"language": {
"processing": "<i class=\"fa fa-spinner fa-spin\"></i>"
}
});
// append data tools
appendDataTools();
// initialize the TableTools and then append to DOM
function appendDataTools() {
var tt = new $.fn.dataTable.TableTools(table, {
// it uses a Flash SWF file to provide the ability to
// copy text to the system clipboard and save files locally.
"sSwfPath": "../swf/copy_csv_xls_pdf.swf",
// select which buttons to display and export only the visible columns
// now the exporting only the selection is broken
"aButtons": [
{
"sExtends": "copy",
"mColumns": "visible",
"bSelectedOnly": true
},
{
"sExtends": "xls",
"mColumns": "visible",
"bSelectedOnly": true
},
{
"sExtends": "print",
"mColumns": "visible",
"bSelectedOnly": true,
"bShowAll": false
}
]
});
var dataTools = $("#dataTableTools");
dataTools.append(tt.fnContainer());
}
});
注意:截至2015-09-04,TableTools扩展程序已停用。看起来正在被Buttons Extension取代。虽然我看不到 print 按钮,但希望很快就能看到它:)