2013-01-17 47 views
0

我初始化.dataTable()方式如下:jQuery的數據表獲得ID

$(document).ready(function(e) { 
    var articles_table = $("table#datatable-articles").dataTable({ 
     'bProcessing': true, 
     'bServerSide': true, 
     'rowHeight': 'auto', 
     "bAutoWidth": true, 
     'sAjaxSource': '/admin/articles/data', 
     sPaginationType: "full_numbers", 
    }); 

於是,我試圖讓id值是在tbody > tr > td:first並將其保存在一個變量,然後隱藏場。沒有運氣,我試過的所有東西都沒用。

var ex = $('table#datatable-articles'); 
    if ($.fn.DataTable.fnIsDataTable(ex)) { 
     console.log(ex.find('tbody tr td:first')); 
     ex.find('tbody tr td:first').css('backgroundColor', 'blue'); 
    } 

/

articles_table.$('tbody tr:odd').css('backgroundColor', 'blue'); 
    console.log(articles_table.find('tbody tr td:first').val()); 
    articles_table.find('tbody tr td:first').html('1'); 

所有DOM的準備上面執行,但隨後的dataTable被初始化,其數據

取代一切的基本問題是:如何獲取的id值從表中的數據,然後隱藏它?

回答

0

這是我結束了,和它的作品...

dataTable()添加了以下

 'fnRowCallback': function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { 
      $(nRow).attr("data-id",aData[0]); 
      return nRow; 
     }