我有一个小问题。我有一个查询,我已作为JSON数据返回,我正在将其加载到datatables.net的数据表中。我有0,1或2的值,我想将它们改为是,否或不适用。
我对js一无所知,我试图实现我在网站上看到的东西,但我仍然无法让它工作。任何帮助将不胜感激。
这是我到目前为止所拥有的
var oTable = $('#test').dataTable({
"aaData": {{ $ecl_staff }},
"sPaginationType": "full_numbers",
"aoColumns": [
{ "mDataProp": "id" },
{ "mDataProp": "full_name" },
{ "mDataProp": "user_number" },
{ "mDataProp": "campus" },
{ "mDataProp": "email" },
{ "mDataProp": "mobile" },
{ "mDataProp": "co_ordinator" },
{ "mDataProp": "job_title" },
{ "mDataProp": "contractor" },
{ "mDataProp": "returning" },
{ "sDefaultContent": "id",
"fnRender": function (oObj) { return "<span class='button-group compact'><a class='button icon-gear with-tooltip modal_link' title='Edit user' href='{{ URL::base() }}/admin/staff/edit_staff/" + oObj.aData['id'] + "'></a> <a class='button icon-card with-tooltip modal_link' title='View Profile' href='{{ URL::base() }}/admin/staff/edit_staff/" + oObj.aData['id'] + "'></a></span>";
}
}
],
"sDom": '<"tbl_tools"CT<"clear">>,<"tbl-tools-searchbox"fl<"clear">>,<"table_content"t>,<"widget-bottom"ip<"clear">>',
"oTableTools": {
"sSwfPath": "../swf/copy_cvs_xls_pdf.swf"
},
});
$("div.tbl-tools-searchbox select").addClass('blue-gradient glossy replacement');
$("div.tbl_tools").addClass('hidden-on-mobile');
$("tfoot input").keyup( function () {
var id = $(this).attr('id').split("-")[1];
oTable.fnFilter( this.value, id );
});
{ "mDataProp": "returning" }
,数据是包含0,1和2的列。
谢谢:))
答案 0 :(得分:0)
你要做的事情很有可能
参考 - DataTables.net Column Usage
var oTable = $('#test').dataTable({
"aaData": {{ $ecl_staff }},
"sPaginationType": "full_numbers",
"aoColumnDefs": [ {
"aTargets": [ 9 ],// index of the returning column
"mRender": function ( data, type, full ) {
if(data == 0){
return "No";
}
if(data == 1){
return "Yes";
}
if(data == 2){
return "N/A";
}
}
} ],
"aoColumnDefs": [ {
"aTargets": [ 10 ],// index of the id column
"mRender": function ( data, type, full ) {
return "<span class='button-group compact'><a class='button icon-gear with-tooltip modal_link' title='Edit user' href='{{ URL::base() }}/admin/staff/edit_staff/" + data + "'></a> <a class='button icon-card with-tooltip modal_link' title='View Profile' href='{{ URL::base() }}/admin/staff/edit_staff/" + data + "'></a></span>";
}
} ],
"sDom": '<"tbl_tools"CT<"clear">>,<"tbl-tools-searchbox"fl<"clear">>,<"table_content"t>,<"widget-bottom"ip<"clear">>',
"oTableTools": {
"sSwfPath": "../swf/copy_cvs_xls_pdf.swf"
}
});