我嘗試將導出按鈕添加到我的數據表,我的表包括選擇框裏面,問題是 - 導出選擇框中包含的所有選項值...一個正在使用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,
....
在
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;
},
任何回答將幫助,不勝感激
剛添加的代碼示例 – benjah