Questions tagged [datatables]

DataTables is a plug-in for the jQuery JavaScript library. It is a highly flexible tool, based upon the foundations of progressive enhancement, which will add advanced interaction controls to any HTML table. Do not use this together with [datatable].

DataTables is a for the . It is a highly flexible tool, based upon the foundations of progressive enhancement, which will add advanced interaction to any .

Do not confuse this tag with which is for table constructs in other languages like .NET's DataTable type! Using both tags together should only be done when displaying .NET DataTable content as jQuery DataTables in a web page.

##Key features:##

  • Variable length pagination
  • On-the-fly filtering
  • Multi-column sorting with data type detection
  • Smart handling of formatted data for display, filtering and sorting
  • Smart handling of column widths
  • Display data from almost any data source
  • DOM, JavaScript array, Ajax file and server-side processing (PHP, C#, Perl, Ruby, AIR, Gears, Python, etc.)
  • Scrolling options for table viewport
  • Supports internationalization
  • jQuery UI ThemeRoller support
  • Rock solid - backed by a suite of 2600+ unit tests
  • Wide variety of plug-ins inc. TableTools, FixedColumns, KeyTable and more
  • It's free!

##Resources:##

##Coding:##

Add recent version of all libraries

<link  href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.21/css/jquery.dataTables.min.css" rel="stylesheet" >
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.21/js/jquery.dataTables.min.js"></script>

###Default HTML table###

For DataTables to be able to enhance an HTML table, the table must be valid, well formatted HTML, with a header (thead) and a body (tbody). An optional footer (tfoot) can also be used.

<table id="example" class="display">
   <thead>
      <tr>
         <th>Company name</th>
         <th>Address</th>
         <th>Town</th>
      </tr>
    </thead>
    <tbody>
       <tr>
          <td>Emkay Entertainments</td>
          <td>Nobel House, Regent Centre</td>
          <td>Lothian</td>
       </tr>
       <tr>
          <td>The Empire</td>
          <td>Milton Keynes Leisure Plaza</td>
          <td>Buckinghamshire</td>
       </tr>
    </tbody>
</table>

###Initializing the plugins:###

After the proper include of the required JavaScript/JQuery libraries the plug-in can be initialized with a few line of code. The text following the # character and the id attribute of the table must be identical.

$(document).ready(function() {
    $('#example').dataTable();
});

###Fiddle:###

  • When asking questions it is a good idea to provide a Fiddle or JS Bin which reproduces your problem. This greatly increases the possibility for others to debug your problems.
20644 questions
98
votes
12 answers

DataTables: Cannot read property 'length' of undefined

I understand this a popular issue, and I have read all the similar questions here on Stack Overflow and other sites (including the datatables website). To clarify, I am using PHP Codeigniter Materliazecss I have also made sure that I received the…
Abdelrahman Shoman
  • 2,882
  • 7
  • 36
  • 61
98
votes
8 answers

Disable automatic sorting on the first column when using jQuery DataTables

I'm using jQuery DataTables and I would like to know if there's possible to disable automatic sorting on the first column of the table? My code looks like this: /* Default class modification */ $.extend(…
Psyche
  • 8,513
  • 20
  • 70
  • 85
91
votes
24 answers

jQuery DataTables: Delay search until 3 characters been typed OR a button clicked

Is there please an option to start the search only after 3 characters have been typed in? I have written a PHP-script for colleagues displaying 20,000 entries and they complain, that when typing a word, the first few letters cause everything to…
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
89
votes
9 answers

How to show all rows by default in JQuery DataTable

Does anybody know how to show all rows by default in jQuery datatable? I have tried this code, but it only shows 10 rows by default. $("#adminProducts").dataTable({ "aLengthMenu": [100] });
Radislav
  • 2,892
  • 7
  • 38
  • 61
89
votes
14 answers

Datatables warning(table id = 'example'): cannot reinitialise data table

I am working with datatables example and getting an error like this when loading page: Datatables warning(table id = 'example'): cannot reinitialise data table. To retrieve the DataTables object for this table, pass no arguments or see the docs for…
vjk
  • 2,163
  • 6
  • 28
  • 42
87
votes
12 answers

DataTables warning: Requested unknown parameter '0' from the data source for row '0'

Does anybody please know, what is wrong with the very simple HTML file below? I am just trying to use an array of objects as the data source for DataTables: tests.html:
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
87
votes
14 answers

Disable sorting on last column when using jQuery DataTables

I'm using jQuery DataTables in a project and I would like to know how to disable sorting for the last column. I want to implement this site-wide. Right now I have the following code:
Psyche
  • 8,513
  • 20
  • 70
  • 85
81
votes
7 answers

How to show empty data message in Datatables

Suppose i get empty data from server sometimes, i want to display No Data found message in DataTables?. How is this possible?
Naruto
  • 9,476
  • 37
  • 118
  • 201
79
votes
13 answers

jquery datatables hide column

Is there a way with the jquery datatables plugin to hide (and show) a table column? I figured out how to reload the table data: using fnClearTable and fnAddData. But my issue is that in one of my views for the table (e.g. a hidden mode) I don't want…
john
  • 2,733
  • 6
  • 23
  • 14
71
votes
11 answers

How to redraw DataTable with new data

I have checked several questions already about this topic here in stackoverflow, but they are all using the old dataTable. I am using DataTable. I populated my DataTable by NOT USING server side, so data are preloaded (JSON) like this : datatable =…
user2881063
  • 1,049
  • 1
  • 10
  • 18
67
votes
12 answers

Datatables on-the-fly resizing

I'm using the marvellous DataTables jQuery plug-in; http://datatables.net/ Added the FixedColumns and KeyTable extras. Now the table does resize prettily when the window size is changed. However, the containing div of the table can also be resized…
Emphram Stavanger
  • 4,158
  • 9
  • 35
  • 63
65
votes
19 answers

disable pagination if there is only one page in datatables

I am implementing datatbales and according to my requirement, most of the things have been resolved except the pagination issue. In my case for every time pagination navigation is displaying. I want to disable the pagination navigation if there is…
Bappa
  • 799
  • 1
  • 9
  • 17
64
votes
9 answers

Change values of select box of "show 10 entries" of jquery datatable

By default, jquery datatable shows 10 by default and has options : 10,25,50,100 How can I change these options?
rjmcb
  • 3,595
  • 9
  • 32
  • 46
63
votes
4 answers

DataTables: Uncaught TypeError: Cannot read property 'defaults' of undefined

When using the Bootstrap integration for DataTables, I see the following error in the console: Uncaught TypeError: Cannot read property 'defaults' of undefined (dataTables.bootstrap.js:20) This causes the pagination controls to not have styles on…
Ryan Kohn
  • 13,079
  • 14
  • 56
  • 81
63
votes
1 answer

dataTable() vs. DataTable() - why is there a difference and how do I make them work together?

The vast majority of the documentation for this plugin indicates that you initialize it with $('#example').dataTable(); However http://www.datatables.net/examples/api/multi_filter_select.html initializes using $('#example').DataTable(); The…
ggutenberg
  • 6,880
  • 8
  • 39
  • 48