layui,导出
table.cache.voucherDetails; // 可以获取全部数据。
/* 导出表格数据 */
form.on('submit(exportdata)', function(datas){
var all_data = table.cache.detailslist;
/*====excel title=================================*/
show_title = new Array();
show_fields = new Array();
var title_arr = show_field.config.cols[0];
for(var i in title_arr) {
show_title.push(title_arr[i]['title']);
show_fields.push(title_arr[i]['field']);
}
show_title = show_title.filter(del_arr_undefined);
show_fields = show_fields.filter(del_arr_undefined);
/*====excel title=================================*/
var export_data_arr = new Array();
var time_to_arr = ['fwstart','fwend','remittance'];
var mobile_to_arr = ['mobile1','mobile2'];
/*整理导出数据,按title顺序整理*/
all_data.forEach(function(val){
var export_data_arr_temp = {};
for(var b in show_fields){
/*===== 这个里面写对导出数据的处理 =============================================*/
if(time_to_arr.includes(show_fields[b])){ // 时间戳转年月日
if(!(typeof(val[show_fields[b]]) == "undefined") && val[show_fields[b]] != ""){
val[show_fields[b]] = formatDate(val[show_fields[b]] * 1000);
}else{
val[show_fields[b]] = '';
}
}
val['billing_type'] = billing_type(val['billing_type']);
/*===== 这个里面写对导出数据的处理 =============================================*/
val['agents'] = val['agents'].replace("<br/>", "");
export_data_arr_temp[show_fields[b]] = val[show_fields[b]];
}
export_data_arr.push(export_data_arr_temp);
});
table.exportFile(show_title, export_data_arr);
return false;
});
/* 筛选数组,删除数组中为undefined的值 */
function del_arr_undefined(element) {
return element != undefined;
}