ben*_*jah 6 export datatables tabletools
我尝试将导出按钮添加到我的数据表中,我的表中包含选择框,问题是 - 它导出选择框中包含的所有选项值...我使用ajax从服务器获取结果然后操纵不同的数据在使用如下dataSrc函数渲染之前:
dataTableInit: function (columns_def) {
var me = this;
me.dataTable_obj = $('#leads_table').DataTable({
"pageLength": per_page,
dom: 'Blfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
],
"order": [order],
"ajax": {
url: route,
type: method,
data: filtering_data,
"dataSrc": function (json) {
return me.setLeadsTableData(json);
}
},
"columns": columns_def,
....
Run Code Online (Sandbox Code Playgroud)
在setLeadsTableData我检查从服务器返回的列然后如果它是一个应该是一个选择框的列我正在改变它模板,如下所示:
setStatusesSelectBox: function (status_obj, lead_id) {
var me = this;
var statuses_list = '';
var bg_color = status_obj.name == "new" ? me.new_status_row_bg_color : '';
$.each(me.client_statuses, function (key, val) {
if (val.id != status_obj.id) {
if (typeof val.is_won !== "undefined" && val.is_won != 0) {
statuses_list += "<option data-icon='fa fa-thumbs-o-up' value='" + val.id + "'>" + val.name + "</option>";
} else if (typeof val.is_lost !== "undefined" && val.is_lost != 0) {
statuses_list += "<option data-icon='fa fa-thumbs-o-down' value='" + val.id + "'>" + val.name + "</option>";
} else {
statuses_list += "<option value='" + val.id + "'>" + val.name + "</option>";
}
} else {
if (typeof val.row_bg_color !== 'undefined') {
bg_color = val.row_bg_color;
}
if (typeof status_obj.is_won !== "undefined" && status_obj.is_won != 0) {
statuses_list += "<option data-icon='fa fa-thumbs-o-up' value='" + val.id + "' selected>" + val.name + "</option>";
} else if (typeof status_obj.is_lost !== "undefined" && status_obj.is_lost != 0) {
statuses_list += "<option data-icon='fa fa-thumbs-o-down' value='" + val.id + "' selected>" + val.name + "</option>";
} else {
statuses_list += "<option value='" + val.id + "' selected>" + val.name + "</option>";
}
}
});
statuses_list += "</select>";
var select_start = "<select name='status' data-show-icon='true' data-row-bg='" + bg_color + "' class='form-control status-select' data-lead-id='" + lead_id + "'>";
;
return select_start + statuses_list;
},
Run Code Online (Sandbox Code Playgroud)
任何答案都会有所帮助,欣赏它
使用exportOptions' format.body回调来控制导出的数据.使用dataTables API查找每个<select>框的当前选定值.这里是第一列和pdf:
buttons: [
{
extend : 'pdf',
exportOptions : {
format: {
body: function( data, row, col, node ) {
if (col == 0) {
return table
.cell( {row: row, column: col} )
.nodes()
.to$()
.find(':selected')
.text()
} else {
return data;
}
}
}
},
...
}
]
Run Code Online (Sandbox Code Playgroud)
table在您的情况下,表实例在哪里me.dataTable_obj.现在只需更改,if (col == 0) {以便它响应您有<select>盒子的列(我不知道).
| 归档时间: |
|
| 查看次数: |
3458 次 |
| 最近记录: |