Abhinav
Abhinav

Reputation: 41

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?

Upvotes: 4

Views: 5080

Answers (3)

Jens Berger
Jens Berger

Reputation: 304

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

Upvotes: 7

SSA
SSA

Reputation: 5493

You can use wrap function:

$('table').wrap('<div class="class-name"></div>');

Upvotes: 2

Jean-Pierre Delacre
Jean-Pierre Delacre

Reputation: 186

Does your table have a unique ID or class? Because then, you could simply use the jQuery function wrap().

Upvotes: 1

Related Questions