2013-04-16 52 views
0

我有一個小問題。我有一個查詢,我已經作爲JSON數據返回,我從datatables.net加載到數據表。我的值是0,1或2,我想將它們改爲yes,no或n/a。我如何編輯datatables.net dataTable中的單元格值

我不知道任何關於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

豈不是更容易的DataTable使用它之前改變數據? – lukeocom

+0

嗨,但我的mysql技能並不是那麼棒。當我讀到有關MySQL中的語句時,它提到了一些關於存儲過程的信息,我沒有這樣做。謝謝 – user1740151

回答

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" 
    } 
}); 
相關問題