代码之家  ›  专栏  ›  技术社区  ›  Akshay

复选框单击jquery datatables不工作的事件

  •  0
  • Akshay  · 技术社区  · 7 年前

    我使用了jQuery数据表 https://datatables.net/ 对于我的网格。 有两个网格,每个网格中都有一个复选框。当复选框被选中/取消选中时,我需要生成一个事件。

    我试过了,但没用。请告诉我我做错了什么。。。。。。。。。。

      $(document).ready(function () {
                $('.cBSAGrid tr td').click(function (event) {
                    alert('0'); 
                });
            });
    

     $(document).ready(function () {
                $('#BSAGrid tr').click(function (event) {
                    alert('0'); 
                });
            });
    

    $.ajax({
                    type: "POST",
                    url: "/BSA/BSAExceptionGrid",
                    data: '{ policynumber: "' + txtpolicy.val() + '",clientname:"' + clientname.val() + '" }',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        div.css("display", "none"); 
    
                        $('#BSAGrid').DataTable({
                            paging: false,
                            searching: false,
                            destroy: true,
                            "bInfo" : false,
                            data: response,
                            columns: [
                                { "data": "Logged_ID" },
                                { "data": "Logged_ID" }, 
                                { "data": "CustomerName" },
                                { "data": "ClientType" }                           
    
                            ], 
                            aoColumnDefs: [
                            {
                                aTargets: [0],    // Column number which needs to be modified
                                mRender: function (o, v) {   // o, v contains the object and value for the column
                                    return '<input type="checkbox" id="chkBSA" name="chkBSA" />';
                                }
                                //,sClass: 'tableCell'       // Optional - class to be applied to this table cell
                            }
                            ,
                             {
                                 aTargets: [1],
                                 visible: false
                             }
                            ],
                            select: {
                                style: 'os',
                                selector: 'td:first-child'
                            },
                            order: [[1, 'asc']]
    
                        });
    
                    },
                    failure: function (response) {
                        alert(response);
                    },
                    error: function (response) {
                        alert(response.responseText);
                    }
                }); 
    

    HTML格式

      <div id="BSAGridContainer" style="display:none;">  
           <table id="BSAGrid" class="cBSAGrid table table-responsive">
                <thead>
                    <tr> 
                        <th></th>
                        <th >Logged_ID</th> 
                        <th>Client Name</th>
                        <th>Client Type</th>
                    </tr>
                </thead> 
            </table> 
        </div>
    
    2 回复  |  直到 7 年前
        1
  •  0
  •   Ali Imran    7 年前

    尝试以下代码:

    $(document).ready(function(){
    $(document).on("change", "#chkBSA", function() {
    alert('click')
    });
    });
    
        2
  •  0
  •   Mauri    7 年前

    您可以在同一列中包含onChange事件侦听器,将其添加到列return text onChange=“gridCheckboxChange(this);”

        3
  •  0
  •   Aman    6 年前

    如果您使用的是bootstrap4自定义复选框,那么在复选框中添加一个类

    .className {left: 0;z-index: 1;width: 1.25rem;height: 1.25rem;}