简体   繁体   English

如何隐藏 data.table 在 javascript 和 jquery 中显示条目?

[英]how to hide data table show entries in javascript and jquery?

I am using DataTable plugin for jQuery and using show entries(datatables_length) to have a dropdown list to select how many entries to be shown on the page at once.我正在为 jQuery 使用 DataTable 插件,并使用 show entries(datatables_length) 将下拉列表设置为 select 一次在页面上显示多少条目。 I also have a small search built in function given by DataTable to search for the desired entry.我还有一个由 DataTable 提供的 function 内置的小型搜索,用于搜索所需的条目。 I am working on to hide the show entries drop down list on the page ONLY IF the DataTable search has not found any matching data in the search bar.仅当 DataTable 搜索未在搜索栏中找到任何匹配数据时,我才致力于隐藏页面上的显示条目下拉列表。 Below is my code.下面是我的代码。 Please help me hide the show entries dropdown list if the search function returns the null or no matching value.如果搜索 function 返回 null 或没有匹配值,请帮我隐藏显示条目下拉列表。

$(document).ready(function() {
       
    $('#table').DataTable() {
        'oLanguage': {
            'sSearch': '<span>Search</span>'
        },
            lengthMenu : [ 5, 10, 15, 20],
            pagingType: 'full_numbers'
        });
        searchForData();
    });

    function searchForData() {
        $('.datatable_filter input[type="search"])
          .attr('placeholder', 'person Id', 'Person name')
          .css({'width':'500px', 'display':'inline-block'});
    }
});

Here the drawCallback option can be used这里可以使用drawCallback选项

$(document).ready( function () {
  var table = $('#table').DataTable({
    drawCallback: function(){
      var api = this.api();
      var records = api.page.info().recordsDisplay;
      var pageMenu = $('div.dataTables_length');
      if (records === 0) {
        pageMenu.hide();
      } else if (pageMenu.css('display') == 'none') {
        pageMenu.show();
      }
      // HERE IS YOUR FUNCTION TO CUSTOM YOUR SEARCH INPUT
      searchForData();   
    }
  });
});

A live example: http://live.datatables.net/pecafifi/2/edit一个活生生的例子: http://live.datatables.net/pecafifi/2/edit

If you are using DataTables version < 1.10 , than you must to use fnDrawCallback option如果您使用的 DataTables版本 < 1.10 ,则必须使用fnDrawCallback选项

I am using DataTable plugin for jQuery and using show entries(datatables_length) to have a dropdown list to select how many entries to be shown on the page at once.我正在使用 jQuery 的 DataTable 插件并使用显示条目(datatables_length)有一个下拉列表来选择一次在页面上显示多少条目。 I also have a small search built in function given by DataTable to search for the desired entry.我还有一个由 DataTable 提供的内置函数来搜索所需的条目。 I am working on to hide the show entries drop down list on the page ONLY IF the DataTable search has not found any matching data in the search bar.我正在努力隐藏页面上的显示条目下拉列表,前提是 DataTable 搜索未在搜索栏中找到任何匹配的数据。 Below is my code.下面是我的代码。 Please help me hide the show entries dropdown list if the search function returns the null or no matching value.如果搜索函数返回空值或没有匹配值,请帮助我隐藏显示条目下拉列表。

$(document).ready(function() {
       
    $('#table').DataTable() {
        'oLanguage': {
            'sSearch': '<span>Search</span>'
        },
            lengthMenu : [ 5, 10, 15, 20],
            pagingType: 'full_numbers'
        });
        searchForData();
    });

    function searchForData() {
        $('.datatable_filter input[type="search"])
          .attr('placeholder', 'person Id', 'Person name')
          .css({'width':'500px', 'display':'inline-block'});
    }
});

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

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