基于条件的数据表绘制(删除搜索,分页,条件显示条目)

时间:2016-12-19 14:06:33

标签: jquery datatables

我一直在研究一个问题..但我还是想不通。

我有一个数据表。这是代码。

$('#tableListUser').DataTable({
    responsive: true,
    "bDestroy": true,
    'iDisplayLength': 10,
    oLanguage: {
        sSearch: ''
    }
});

在我有要求之前,一切似乎都很好。

这就是我想要的

  1. 如果行数< 10 - > 分页,显示参赛作品,搜索 必须删除
  2. 如果行数> 10 - >应该显示分页,显示条目,搜索 (这就是我现在所拥有的)
  3. 读了一下后,我明白了 drawCallback()的范围。但是我是数据表上的菜鸟。这甚至可能吗?请指教......

    提前致谢。

1 个答案:

答案 0 :(得分:1)

$('#tableListUser').DataTable({
responsive: true,
bDestroy: true,
iDisplayLength: 10,
oLanguage: {
    sSearch: ''
},
fnDrawCallback: function( oSettings ) {
    if(oSettings.fnRecordsDisplay() < 10 &&!$('#tableListUser' + '_filter').find(":input").val()){  
      $('#tableListUser' + '_length').hide();        
      $('#tableListUser' + '_filter').hide();        
      $('#tableListUser' + '_paginate').hide();
    }
    else{   
      $('#tableListUser' + '_length').show();        
      $('#tableListUser' + '_filter').show();  
      $('#tableListUser' + '_paginate').show();  
    }

}
});

我为你建立了一个小小提琴: https://jsfiddle.net/c1dgxq78/1

相关问题