标签:
Datatable 实现ajax动态分页、设计各列单元格dom格式。
function initiateDataTableByAjax(tableObj) { require(['datatables', 'datatables-tabletools'], function() { tableObj.downLoadURL="/tabledbexport"+tableObj.url.slice("/tabledb".length); var table = $('#' + tableObj.id).dataTable({ "paging" : tableObj.isPaging, "ordering" : tableObj.ordering, "dom" : 'T<"clear">lfrtip', "bProcessing" : false, "aoColumnDefs" : tableObj.aoColumnDefs? tableObj.aoColumnDefs:[{ "aTargets": [ '_all' ], "mRender": function ( data, type, full ) { if(data!=null){ return '<div class="excoll">'+data+'</div>'; }else{ return ''; } } }], "processing" : true, "serverSide" : true, "tableTools" : { "sSwfPath" : "/bower_components/datatables-tabletools/swf/copy_csv_xls_pdf.swf", "aButtons" : [{ "sExtends" : "xls", "sTitle" : tableObj.exportName, "sAction" : "flash_copy", "fnClick" : function(nButton, oConfig, oFlash) { var params = table.fnSettings().aaSorting;//[0,"asc"] var search_value=table.fnSettings().oPreviousSearch.sSearch; var connector = "?draw=0&"; if(tableObj.downLoadURL.indexOf("?")!=-1){ connector = "&draw=0&"; } var export_url= tableObj.downLoadURL+connector+"orderColumn="+params[0][0]+"&orderDir="+params[0][1]+"&search="+search_value; location.href = export_url; } }] }, "ajax" : { "url" : tableObj.url, error: function (xhr, error, thrown) { var wid = $('#' + tableObj.id).parents(".widget-content").parent().parent().attr("id"); xhr.responseText = thrown; showErrorMsg(wid, xhr); } }, columns : addAttributesForSomeColumns(tableObj.columnsSetting), "fnDrawCallback" : function(oSettings) { if(tableObj.fnDrawCallback){ tableObj.fnDrawCallback(); } } }); }); }function addAttributesForSomeColumns(columnsSetting) { var columns_array = new Array(); if (columnsSetting.showColumns) { for (i in columnsSetting.showColumns) { var cc = { data : columnsSetting.showColumns[i], }; columns_array.push(cc); }; } else { for (var i = 0; i < columnsSetting.length; i++) { var cc = { data : i, }; columns_array.push(cc); }; } if (columnsSetting.edit_columns) { $.each(columnsSetting.edit_columns, function(index, element) { columns_array[element[0]].data = null; columns_array[element[0]].render = element[1]; }); }; return columns_array; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/u010403387/article/details/46966163