2014-09-10 82 views
0

如何在數據表中獲得TD的TH?現在我有一個代碼,我可以用它來對數據表添加到TD的屬性:在數據表中獲取TD的TH

"fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { 
    $('td', nRow).attr("title","PUMMM"); 
    //takes the tds from the row and assigned title attribute 
} 

我想要做的就是把不同的屬性取決於具體的TD有頭。

回答

1

你的意思是這樣的嗎?對不起,我不知道這個插件...

var columNumber = 0; 
"fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { 
    $('td, th', nRow).each(function(){ 
     var $this = $(this); 
     if($this[0].tagName == "TD"){ 
       switch(columnNumber) 
       { 
        case 0: 
         $this.attr("title","Column 0"); 
         break; 

        case 1: 
         $this.attr("title","Column 1"); 
         break; 
        . 
        . 
        . 
        . 

       } 
       columnNumber++; 
     } 

    }); 
} 
+0

謝謝,我設法用你的代碼進行一些修改,以解決我的問題,我做了一個編輯,我分配了一個數字,以每列,所以現在我可以知道我正在處理哪一列。請批准修改以投票回答。 – Vito 2014-09-11 14:16:39