数据表列过滤

时间:2020-01-08 03:40:24

标签: datatables

请求帮助,在我的程序中,我使用ajax调用从url加载表数据,一旦加载数据,当我在列过滤器框中键入文本时,该数据将为每个列创建一个列过滤器被过滤,然后过滤器消失,因此需要您的帮助来避免在键入文本时如何避免列过滤器的消失,以下是我尝试过的代码

<script type="text/javascript">
$(document).ready(function(){
    $("input[type='radio']").on('click', function(){
        var rvalue = $("input[name='Servs']:checked").val();
        var surl = '/Slist/' + rvalue;

                var table = $("#Server").DataTable({
                        destroy: true,
                        ajax: {
                                url: surl,
                                dataSrc: "",
                                method: "GET",
                                xhrFields: { withCredentials: true }
                        },
                        columns: [
                                        { title: "Server", data: "Server", className: "text-center h8 px-0" },
                                        { title: "Location",  data: "location", className: "text-center h8 px-0" },
                                        { title: "Rack",  data: "rack", className: "text-center h8 px-0" }
                        ],
                        filter: false,
                        searching: true,
                        initComplete: function () {
                            $('input[type=search]').val('');
                            $('#Server thead tr').clone(true).appendTo( '#Server thead' );
                            $('#Server thead tr:eq(1) th').each( function (i) {
                                var title = $(this).text();
                                $(this).html( '<input type="text" placeholder="'+title+'" />' );

                                $( 'input', this ).on( 'keyup change', function () {
                                if ( table.column(i).search() !== this.value ) {
                                    table
                                    .column(i)
                                    .search( this.value )
                                    .draw();
                                }
                                });
                            } );
                        }   
                });
        });     
});                     
</script>

0 个答案:

没有答案
相关问题