4

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?

4
  • what output you expect? Commented Dec 29, 2014 at 10:58
  • The output as I shown in my question in which a div around table. Commented Dec 29, 2014 at 11:00
  • Can you not just add class-name to the table itself? Commented Dec 29, 2014 at 11:03
  • no this will not solve my purpose. I need to add a div around table. Commented Dec 29, 2014 at 11:04

3 Answers 3

7

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

Sign up to request clarification or add additional context in comments.

Comments

2

You can use wrap function:

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

Comments

1

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

2 Comments

I can wrap the table in a div using this but then datatable is not working on that table.
Pagination doesn't work, you mean? How about applying .datatable() first and then, in the callback, using wrap() to add your div? What's your final objective?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.