DataTable : How to hide the pagination and only show it as need?

后端 未结 6 1427
耶瑟儿~
耶瑟儿~ 2021-02-13 01:51

I have 2 tables that are using DataTable jQuery Plug-in. I wondering if there is a way to hide my pagination on the bottom right of my table.

6条回答
  •  情深已故
    2021-02-13 01:56

    $(this) did not work for me, probably because I am using TypeScript. So I used a different approach to get the JQuery element for the table wrapper and the DataTables API. This has been inspired by the answer of BitOfUniverse and tested with DataTables 1.10.

    TypeScript:

    'drawCallback': (settings: any) => {
          // hide pager and info if the table has NO results
          const api = new $.fn.dataTable.Api(settings);
          const pageCount = api.page.info().pages;
    
          const wrapper = $('#' + settings.sTableId).closest('.dataTables_wrapper');
          const pagination = wrapper.find('.dataTables_paginate');
          const info = wrapper.find('.dataTables_info');
    
          pagination.toggle(pageCount > 0);
          info.toggle(pageCount > 0);
     }
    

提交回复
热议问题