数据表分别搜索多个列 [英] Datatables search multiple columns individually

查看:81
本文介绍了数据表分别搜索多个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按数据表中的列进行过滤,但我不明白为什么仅在两列中都存在该行的情况下才能找到该行,我希望如果在另一列中存在该行,则搜索将找到结果.

I am trying to do a filter by column in the datatable and I am not getting why the row is only found if it exists in the two columns, I would like that if it had in another column the search would find result.

我尝试这样做,但是当我使用此代码时,它仅在第一列中搜索结果,例如第四栏.并忽略其余部分.

I tried doing this but when i use this code it only searches the result in the first column, E.g. 4th Column. and ignores the rest.

    table.column([4,5]).search($(this).val()).draw();


$("#select-categories").each( function ( i ) {
                var select = $('<select class="form-control"><option value="" class="optionGroup">Todas</option></select>')
                      .appendTo( $(this).empty() )
                      .on( 'change', function () {
                          table
                              .column(2).search( $(this).val() )
                              .draw();
                      });



                documentosCatRef.on('value', function(data){
                  categoria = data.val();
                  for(var cat in categoria){
                    subcategoria = categoria[cat].subcategorias
                    select.append( '<option value="'+categoria[cat].titulo+'" class="optionGroup">'+categoria[cat].titulo+'</option>'+carregaSubcategoria(subcategoria)+'')
                  }
                })

                function carregaSubcategoria(subcategoria){
                  a = []
                  i = 0;
                  option = ""
                  for(var subcats in subcategoria){
                    a[i] = subcategoria[subcats].nome
                    i++
                  }
                  i = 0;
                  for (var subcat in a){
                  option += '<option value="'+a[subcat]+'">&nbsp;&nbsp;&nbsp;'+a[subcat]+'</option>'
                  }
                  return option;
                }
              });


<div id="tableCustom_filter" class="dataTables_wrapper.no-footer dataTables_filter">
            <label style="display: inline-block;">Filtrar por Categoria:</label>
            <div style="display: inline-block;" id="select-categories"></div>
          </div>

推荐答案

使用 columns().search() 进行多列搜索.

Use columns().search() to search in multiple columns.

table.columns([4,5]).search($(this).val()).draw();

这篇关于数据表分别搜索多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆