简体   繁体   English

单击时出现DataTables搜索栏

[英]DataTables search bar appear on click

I am using dataTables in a small jquery app i am making. 我在做的一个小型jquery应用程序中使用dataTables I basically have a search bar which i only want to show if i click on the search icon. 我基本上有一个搜索栏,如果我单击搜索图标,我只想显示它。 In order to make the search bar disappear "bFilter": true, should be set to false. 为了使搜索栏消失“ bFilter”:true,应设置为false。 This is a fiddle i have created and what i have so far. 这是我创造的小提琴 ,到目前为止我所拥有的。

The following is what i tried but it does not work. 以下是我尝试过的方法,但是它不起作用。

<script>
    (document).ready( function () {
      $('#example').dataTable( {
        "bPaginate": false,
        "bFilter": false,
       "oLanguage": { "sSearch": "" } 



      } );

      $('.dataTables_filter input').attr("placeholder", "enter seach terms here");
    } );

    $('#search').click(function(e) {  

      $('#example').dataTable( {

        "bFilter": true




      } );

        });
</script>

In this i basically set the bfilter to false initially to make it not appear and try to set it to true upon clicking the search icon. 在这种情况下,我基本上将bfilter最初设置为false以使其不显示,并在单击搜索图标时尝试将其设置为true。 Can someone please help? 有人可以帮忙吗? Also for some reason my search icon css got messed up idk why. 同样由于某种原因,我的搜索图标css搞砸了idk为什么。 Please advice. 请指教。

This will hide your filter input box and show it when you click the search icon. 这将隐藏您的过滤器输入框,并在您单击搜索图标时显示它。

CSS: CSS:

#example_filter {
    display: none;
}

JS: JS:

$('#search').click(function(e) {  
    $('#example_filter').show();
});

DEMO: JSFIDDLE 演示: JSFIDDLE

Alternative, you can use .toggle() so a second click will hide the box again. 或者,您可以使用.toggle(),因此再次单击将再次隐藏该框。

$('#search').click(function(e) {  
    $('#example_filter').toggle();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM