【问题标题】:How to get the column index in which radio button has selected in jquery datatables如何获取在jQuery数据表中选择了单选按钮的列索引
【发布时间】:2014-12-04 13:58:58
【问题描述】:

您好,我想知道单选按钮在数据表中选择的列索引。

这是我的数据表代码:

$(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;
                         }

                     }

                  ]
   });

  });

这里是获取所选列索引和所选列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);
 });

【问题讨论】:

    标签: jquery jquery-ui datatables jquery-datatables


    【解决方案1】:

    那是因为您只是在遍历选中的单选按钮。使用:

    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);
    });
    

    【讨论】:

    • 我想要列索引,无论是从第一列还是第三列选择的单选按钮。
    • 是的,我试过了,它显示的列数像 1,16,18
    • 你能分享一下小提琴吗??
    • 在每一行中,任何一个单选按钮都应该被​​启用,在这个链接中它只启用一个单选按钮
    • 那是完全不同的问题。
    【解决方案2】:
     var oTable = $('#ReportTable').dataTable();
      $("input:checked", oTable.fnGetNodes()).each(function(){
          var tdColumn = $(this).closest("td");
          rowId= $(this).val();
          columnIndex= tdColumn.index();
          alert(columnIndex);
    
        });
    

    【讨论】:

      猜你喜欢
      • 2011-07-20
      • 1970-01-01
      • 2011-09-23
      • 1970-01-01
      • 2015-03-28
      • 2012-12-15
      • 1970-01-01
      • 1970-01-01
      • 2013-03-01
      相关资源
      最近更新 更多