Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery插件数据表在过滤后消失_Jquery_Jquery Plugins_Datatables - Fatal编程技术网

Jquery插件数据表在过滤后消失

Jquery插件数据表在过滤后消失,jquery,jquery-plugins,datatables,Jquery,Jquery Plugins,Datatables,我正在使用Jquery插件datatables对表中的信息进行排序,但在使用定制的表过滤器后,数据表插件将消失 以下是我的数据表的代码: $(document).ready(function() { $('#loans_table').DataTable( { dom: "<'row'<'col-sm-12'l>>" + "<'row'<'col-sm-12'tr>>" + "<'r

我正在使用Jquery插件datatables对表中的信息进行排序,但在使用定制的表过滤器后,数据表插件将消失

以下是我的数据表的代码:

$(document).ready(function() {
    $('#loans_table').DataTable( {
        dom: "<'row'<'col-sm-12'l>>" + 
        "<'row'<'col-sm-12'tr>>" + 
        "<'row'<'col-sm-12'p>>",
        "language": {
            "paginate": {
                "previous": "&lt;",
                "next": "&gt;"
            },
            "lengthMenu": '<select>'+
                '<option value="-1">{{ 'text.show_all'|trans }}</option>'+
                '<option value="10">{{ 'text.show'|trans }} 10</option>'+
                '<option value="25">{{ 'text.show'|trans }} 25</option>'+
                '<option value="50">{{ 'text.show'|trans }} 50</option>'+
                '</select>',
        },
        "iDisplayLength": -1,
        "pagingType": "simple_numbers",
        "order": [],
        "columnDefs": [ {
        "targets" : 'no-sort',
        "orderable": false,
        }],
        "bDestroy" : true,
     } );
} );
$(文档).ready(函数(){
$(“#贷款表”)。数据表({
dom:“+
"" + 
"",
“语言”:{
“分页”:{
“以前的”:“,
“下一个”:”
},
“长度菜单”:“+
“{”text.show|u all“{trans}”+
“{”text.show“{trans}}10”+
“{”text.show“{trans}}25”+
“{”text.show“{trans}}50”+
'',
},
“iDisplayLength”:-1,
“pagingType”:“简单编号”,
“订单”:[],
“columnDefs”:[{
“目标”:“无排序”,
“可订购”:错误,
}],
是的,
} );
} );
下面是过滤器的代码:

$('#filter-form').on('submit', function(e) {
    e.preventDefault();
    var valid = true;
    $(this).find('input[type=text]').each(function() {
      var value = this.value;
      if (value && (!$.isNumeric(value) || value < 0) ) {
        $(this).parent().addClass('has-error');
        console.log(value);
        valid = false;
      } else {
        $(this).parent().removeClass('has-error');
      }
    });
    if (valid) {
      $.ajax({
        type: "POST",
        url: Routing.generate('app_filter'), // call ApplicationController:filterAction()
        data: $(this).serialize(), // send form data
        //dataType: 'json', // what data accept, html?
        timeout: 60000, // how long to wait for response
        success: function(response) {
          $('#ajax-update').html(response); // insert response data into table
          knp.init(options);
        },
        error: function() {
          $('#match').text('Problem!'); // smth to show if error
        }
      });
    }
 });
$('filter form')。关于('submit',函数(e){
e、 预防默认值();
var valid=true;
$(this).find('input[type=text]')。each(function(){
var值=此值;
if(值&(!$.isNumeric(值)| |值<0)){
$(this.parent().addClass('has-error');
console.log(值);
有效=错误;
}否则{
$(this.parent().removeClass('has-error');
}
});
如果(有效){
$.ajax({
类型:“POST”,
url:Routing.generate('app_filter'),//调用ApplicationController:filterAction()
数据:$(this).serialize(),//发送表单数据
//数据类型:“json”,//接受什么数据,html?
超时:60000,//等待响应的时间
成功:功能(响应){
$('#ajax update').html(响应);//将响应数据插入表中
knp.init(选项);
},
错误:函数(){
$('#match').text('Problem!');//smth显示是否有错误
}
});
}
});

有没有人遇到过类似的问题?

通过在$(“#loans_table”)之前写入table=来修复它。DataTable({

通过清除、删除表并再次对其进行初始化。如下所示:

$('#filter-form').on('submit', function(e) {
    e.preventDefault();
    var valid = true;
    $(this).find('input[type=text]').each(function() {
      var value = this.value;
      if (value && (!$.isNumeric(value) || value < 0) ) {
        $(this).parent().addClass('has-error');
        console.log(value);
        valid = false;
      } else {
        $(this).parent().removeClass('has-error');
      }
    });
    if (valid) {
      $.ajax({
        type: "POST",
        url: Routing.generate('app_filter'), // call ApplicationController:filterAction()
        data: $(this).serialize(), // send form data
        //dataType: 'json', // what data accept, html?
        timeout: 60000, // how long to wait for response
        success: function(response) {
        $('#ajax-update').html(response); // insert response data into table
        knp.init(options);
        if (table) table.clear();

        //reinitialise the dataTable   
        table = $('#loans_table').DataTable({
        destroy: true,
        dom: "<'row'<'col-sm-12'l>>" + 
        "<'row'<'col-sm-12'tr>>" + 
        "<'row'<'col-sm-12'p>>",
        "language": {
            "paginate": {
                "previous": "&lt;",
                "next": "&gt;"
            },
            "lengthMenu": '<select>'+
                '<option value="-1">{{ 'text.show_all'|trans }}</option>'+
                '<option value="10">{{ 'text.show'|trans }} 10</option>'+
                '<option value="25">{{ 'text.show'|trans }} 25</option>'+
                '<option value="50">{{ 'text.show'|trans }} 50</option>'+
                '</select>',
        },
        "iDisplayLength": -1,
        "pagingType": "simple_numbers",
        "order": [],
        "columnDefs": [ {
        "targets" : 'no-sort',
        "orderable": false,
        }]
        });
        },
        error: function() {
          $('#match').text('Problem!'); // smth to show if error
        }
      });
    }
    $(this).find('[type=submit]').blur();
  });
$('filter form')。关于('submit',函数(e){
e、 预防默认值();
var valid=true;
$(this).find('input[type=text]')。each(function(){
var值=此值;
if(值&(!$.isNumeric(值)| |值<0)){
$(this.parent().addClass('has-error');
console.log(值);
有效=错误;
}否则{
$(this.parent().removeClass('has-error');
}
});
如果(有效){
$.ajax({
类型:“POST”,
url:Routing.generate('app_filter'),//调用ApplicationController:filterAction()
数据:$(this).serialize(),//发送表单数据
//数据类型:“json”,//接受什么数据,html?
超时:60000,//等待响应的时间
成功:功能(响应){
$('#ajax update').html(响应);//将响应数据插入表中
knp.init(选项);
if(table)table.clear();
//重新初始化数据表
表=$(“#贷款表”)。数据表({
摧毁:没错,
dom:“+
"" + 
"",
“语言”:{
“分页”:{
“以前的”:“,
“下一个”:”
},
“长度菜单”:“+
“{”text.show|u all“{trans}”+
“{”text.show“{trans}}10”+
“{”text.show“{trans}}25”+
“{”text.show“{trans}}50”+
'',
},
“iDisplayLength”:-1,
“pagingType”:“简单编号”,
“订单”:[],
“columnDefs”:[{
“目标”:“无排序”,
“可订购”:错误,
}]
});
},
错误:函数(){
$('#match').text('Problem!');//smth显示是否有错误
}
});
}
$(this.find('[type=submit]').blur();
});

请举例说明您的问题。制作一把小提琴来解释问题!!