dtfpznrbn503027700 2017-02-03 09:46
浏览 154

bootstrap数据表自定义下拉过滤器

I'm using bootstrap datatables in codeigniter project in footer i included this datatables js and initialized like

$('.datatable').dataTable({
            "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span12'i><'span12 center'p>>",
            "sPaginationType": "bootstrap",
            "oLanguage": {
            "sLengthMenu": "_MENU_ records per page"
            }
        } );

Now i want custom filters in required list page on required column i tried as

<select id="s" name="s">
<option value="1">Hyd</option>
<option value="2">Warangal</option>
</select>

and js as

<script>
$(document).ready(function(){
    $('#s').change( function() {
        //alert($(this).val());
oTable.fnFilter( $(this).val(), 2 );
} );
});
</script>

I want to filter using drop downlist for city.

  • 写回答

2条回答 默认 最新

  • duangouhui0446 2017-02-03 11:03
    关注

    You can do this in this way :

           $('.datatable').dataTable({
           "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span12'i><'span12 center'p>>",
           "sPaginationType": "bootstrap",
           "oLanguage": {
               "sLengthMenu": "_MENU_ records per page"
           },
           initComplete: function() {
               this.api().columns().every(function() {
                   $('#s').change(function() {
    
                       var val = $.fn.dataTable.util.escapeRegex(
                           $(this).val()
                       );
    
                       column.search(val ? '^' + val + '$' : '', true, false).draw();
                   });
               });
           }
    
       });
    

    Source

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记