【发布时间】:2020-07-05 02:42:21
【问题描述】:
好的,我有一个数据表,我正在尝试添加导出到 CSV 的功能。我似乎无法让它导出 isAuthenticated/isDisabled 列的实际值。导出时这些列的值为空白,可能是因为我使用 columndefs 在这些列中显示图像,而不是显示源数据。
我是否生成了错误的列值,或者我应该向哪个方向导出这些列的实际真/假值?
<script type="text/javascript">
$(document).ready(function () {
var dTable = $('#UserList').DataTable({
"processing": true, // for show progress bar
"serverSide": false, // for process server side
"filter": true, // this is for disable filter (search box)
"orderMulti": false, // for disable multiple column at once
"pageLength": 10,
"dom": '<"html5buttons"B>lTfgitp</div>',
"buttons": [
{ extend: 'excel', title: 'Tool Users' }
],
"ajax": {
"url": "/Supervisor/UserData",
"type": "POST",
"datatype": "json"
},
"columns": [
{ "data": "id", "name": "id", "width": "18%" },
{ "data": "fullName", "name": "fullName", "autoWidth": true },
{ "data": "email", "name": "Email", "autoWidth": true },
{ "data": "isAuthenticated", "name": "isAuthenticated", "width":"8%" },
{ "data": "isDisabled", "name": "isDisabled", "width": "8%" },
{
"render": function (data, type, full, meta)
{ return '<a class="btn btn-info ManageUsersBtn" href="/Supervisor/EditUser/' + full.id + '">Edit</a> '; }
}
],
"columnDefs": [
{
"render": function (data, type, row) {
return (data === true) ? '<span class="glyphicon glyphicon-ok text-navy"></span>' : '<span class=" glyphicon glyphicon-remove text-danger"></span>';
},
"targets": 3
},
{
"render": function (data, type, row) {
return (data === true) ? '<span class="glyphicon glyphicon-remove text-danger"></span>' : '<span class=" glyphicon glyphicon-ok text-navy"></span>';
},
"targets": 4
}
],
"fnCreatedRow": function (nRow, aData, iDataIndex) {
if (aData.isAuthenticated) {
}
else {
$('td:eq(5)', nRow).append('<a class="btn btn-info ManageUsersBtn" onclick=AuthenticateUser("' + aData.id + '","' + aData.firstName + '","' + aData.lastName + '")>Authorize</a> ' ) ;
}
if (aData.isDisabled) {
$('td:eq(5)', nRow).append('<a class="btn btn-info ManageUsersBtn" onclick=EnableUser("' + aData.id + '","' + aData.firstName + '","' + aData.lastName + '")>Enable</a> ') ;
}
else {
$('td:eq(5)', nRow).append('<a class="btn btn-danger ManageUsersBtn" onclick=DisableUser("' + aData.id + '","' + aData.firstName + '","' + aData.lastName + '")>Disable</a> ') ;
}
},
});
});
【问题讨论】:
标签: javascript jquery datatables export-to-csv