2014-12-04 84 views
1

嗨我想知道單選按鈕已在數據表中選擇的列索引。如何獲得單選按鈕在jQuery數據表中選擇的列索引

這裏是我的數據表代碼:

$(document).ready(function() { 
table=$('#ReportTable').dataTable({ 
    "bProcessing": true, 
    "bPaginate": false, 
    "bJQueryUI": true, 
    "ajax" :{ 
     url: 'ajax_call.php', 
     type: "POST", 
     data: { 
      action:'loadEmailData' 
     } 
    }, 
    "columnDefs": [ 
        { "aTargets": [0], 
         "mRender": function(data, type, full) 
         { 
          id=full[3]; 
          var returnval = "<td><input type='radio' name='chkNew"+id+"' class='call-checkbox' value="+id+" id=\"chkNew'"+id+"'\" /></td>"; 
           return returnval; 
         } 

        }, 
        { "aTargets": [1], 
         "mRender": function(data, type, full) 
         { 
          id=full[3]; 
          var returnval = "<td><input type='radio' name='chkNew"+id+"' class='call-checkbox' value="+id+" id=\"chkSubmit'"+id+"'\" /></td>"; 
           return returnval; 
         } 

        }, 
        { "aTargets": [2], 
         "mRender": function(data, type, full) 
         { 
          id=full[3]; 
          var returnval = "<td><input type='radio' name='chkNew"+id+"' class='call-checkbox' value="+id+" id=\"chkDeploy'"+id+"'\"/></td>"; 
          return returnval; 
         } 

        } 

        ] 
    }); 

    }); 

這裏是函數來獲得所選擇的coulmn指數和所選列的ID:這是警報柱像0.1的指數。如果我點擊第1和第3欄也很警覺0,1,應該警惕0,2

var oTable = $('#ReportTable').dataTable(); 
    var rowcollection = oTable.$('input[type="radio"]:checked', {"page": "all"}); 
    rowcollection.each(function(index,elem){ 
    var checkbox_value = $(elem).val(); 

    arr[index]=checkbox_value; 
    alert(index); 
}); 

回答

0
var oTable = $('#ReportTable').dataTable(); 
    $("input:checked", oTable.fnGetNodes()).each(function(){ 
     var tdColumn = $(this).closest("td"); 
     rowId= $(this).val(); 
     columnIndex= tdColumn.index(); 
     alert(columnIndex); 

    }); 
0

也就是說監守你只遍歷檢查單選按鈕。用途:

rowcollection.each(function(index,elem){ 
var checkbox_value = $(elem).val(); 
    var globalindex = $(this).closest('tr')find('input[type="radio"]').index(this); 
    arr[globalindex]=checkbox_value; 
    alert(globalindex); 
}); 
+0

我想列索引是否從第一或第三列選中的單選按鈕。 – user3829086 2014-12-04 14:06:14

+0

這應該起作用。你試過嗎? – 2014-12-04 14:08:52

+0

是的,我試過了,它顯示的列數像1,16,18 – user3829086 2014-12-04 14:20:05

相關問題