没有结果找到数据表时如何启用按钮

How enable button when no results found datatables

<script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
                responsive: true
        });
    });
    </script>
<script>
$(document).ready(function () {

   $('#dataTables-example').dataTable( {
    "fnDrawCallback": function( oSettings ) {
        if ($(".dataTables_empty")[0]) {
            $('#newclient').prop("disabled", false);
        } else {
            $('#newclient').prop("disabled", true);
        }
    }
  } );
});
</script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
    <script src="//cdn.datatables.net/plug-ins/3cfcc339e89/integration/bootstrap/3/dataTables.bootstrap.js"></script>
 <link href="//cdn.datatables.net/plug-ins/3cfcc339e89/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">
    <link href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css" rel="stylesheet">    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">

</head>

<body>


                         <div class="add-client"><button type="button" class="btn btn-primary btn-sm" id="newclient"  disabled="true">Add Client</button></div>
                    
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th>Name</th>
                                            <th>File Number</th>
                                            <th>Department</th>
                                            <th>Date</th>
                                            <th>User Name</th>
                                            <th>Password</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr class="odd gradeX">
                                            <td><a href="view-client.html">Mbello Elizabeth</a></td>
                                            <td>954687</td>
                                            <td>w547</td>
                                            <td>October 15 2013</td>
                                            <td>Mbello</td>
                                            <td>cfhqsuvx</td>
                                        </tr>

                                    </tbody>
                                </table>

我正在使用数据表,当搜索后没有找到结果时我需要启用一个按钮,请任何人帮助我。

谢谢

它在这里可以用,但在我的页面上不能用,我不知道是什么问题

您可以使用 DataTables 绘制回调来查明当前 table 中是否没有结果。 fnDrawCallback

这是一个简单的fiddle检查如何在搜索没有结果后启用按钮。

Javascript:

$(document).ready(function () {
  $('#example').dataTable( {
    "fnDrawCallback": function( oSettings ) {
        if ($(".dataTables_empty")[0]) {
            $('#test').prop("disabled", false);
        } else {
            $('#test').prop("disabled", true);
        }
    }
  } );
});