Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a div on table with using jquery datatables?

I am using jQuery data table to manage tables. In this I need to add a div on table only not on the pagination div like below

<div class="class-name"> <table></table> </div> <div class="dataTables_paginate paging_simple_numbers"></div>

Can someone help me in this?

like image 561
Abhinav Avatar asked Oct 17 '25 13:10

Abhinav


1 Answers

The question is old, but today I had the same problem. So here is the "official" solution:

In the JavaScript part where you initialize the DataTable, you can modify the generated DOM like this:

$('table').DataTable( {
    ...,
    dom: '<"class-name"t>p'
});

Where

  • <"class-name" translates to <div class="class-name">
  • t is replaced with the table (<table>...</table>)
  • >closes the div as </div>
  • p renders the pagination elements

The DataTables documentation explains the available options: https://datatables.net/examples/basic_init/dom.html

like image 124
Jens Berger Avatar answered Oct 19 '25 10:10

Jens Berger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!