How to add a title to a datatables table?

417 views Asked by At

I have a DataTables table, and I want to put a title on the table to the left of the search box, like this:

enter image description here

I've tried a few things from Goog and the docs, such as floating an element above the table and caption, which don't look great and look even worse when styling is applied.

Looking through the elements, there seems to be a space already there and available for a title, but I don't know how to access it:

enter image description here

How can I add a title to a DataTables table so it's inline and to the left of the search area.

1

There are 1 answers

0
Alex On

A possible solution could be to modify the structure of the dom.

You can add for example a div with a class name in your table config

'dom' : '<"my-class">'

and once the table is fully created you can insert some text using jquery

'initComplete' : function( settings, json ) {
     $('.my-class').html('Datatable title');
}

I hope I was helpful