2014-12-04 80 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

相关问题