【问题标题】:DataTable Custom Search BoxDataTable 自定义搜索框
【发布时间】:2018-01-24 10:14:30
【问题描述】:

好的。我是 DataTables 的新手,最近我需要找到一种方法来为 Datatables 网格添加我自己的搜索框,但失败了。我在 Datatables.net 论坛和 Stackoverflow 上寻找解决方案,但没有一个解决方案适用。尽管后来结合了两种解决方案,并且感谢 Jsfiddle,但我设法找到了可行且可重复的方法。

这只是我分享我认为对像我这样的初学者有用的东西,所以你可以根据自己的喜好来对待它。

【问题讨论】:

    标签: javascript jquery html twitter-bootstrap-3 datatables


    【解决方案1】:

    HTML

    <input type="text" class="column_filter form-control input-lg" id="col0_filter" size="40">
    
        <table class="table" id="grid1">
            <thead>
                <tr>
                    <th>MotherTag</th>
                    <th>Projected Delivery Date</th>
                    <th>SPPO</th>
                    <th>Batch Qty</th>
                    <th>PO</th>
                    <th>Select</th>
            </thead>
                    <tr>
                    <td>
                        bla bla
                    </td>
                    </tr>
         </table>
    

    JavaScript/Jquery

    <script type='text/javascript'>
        function filterColumn ( i ) {
            $('#grid1').DataTable().column( i ).search(
                $('#col0_filter').val()
            ).draw();
        }
    
        $(document).ready(function() {
            $('#grid1').DataTable();
    
            $('input.column_filter').on( 'keyup click', function () {
                filterColumn(0);
            } );
        } );
    </script>
    

    【讨论】:

      猜你喜欢
      • 2020-03-09
      • 2013-04-03
      • 2018-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      • 2015-05-21
      • 1970-01-01
      相关资源
      最近更新 更多