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
4
votes
3 answers

jQuery / DataTables: how to change pagination color

I am using the jQuery DataTables plugin (version 1.9.4) and would like to change the color of the pagination. With CSS I am able to change their background color but I couldnt find a way to change the font color and font hover color for the anchor…
user2571510
  • 11,167
  • 39
  • 92
  • 138
4
votes
2 answers

datatables select first row onload

I'm trying to auto select first row of table when data is loaded for the first time and failing to do that. How do I auto select first row of table when table loads for the first time? This html doesn't work:
user2959594
  • 363
  • 1
  • 4
  • 5
4
votes
2 answers

How to get the number of pages in DataTables

I am working with DataTables and I need to know the current number of pages that a table holds (this certainly depends on the number of rows per page and the total number of rows and may change by user-action). Does anybody know how to access this…
Mannimalte
  • 204
  • 2
  • 12
4
votes
2 answers

couldn't find file 'dataTables/jquery.dataTables' Rails 4

I'm following the rails casts #340 to implement data tables in my application. Following all the steps I get this error: couldn't find file 'dataTables/jquery.dataTables' I'm using rails 4 and I found that some files that mentions in the tutorial…
LeoJ
  • 57
  • 2
  • 6
4
votes
0 answers

Put bootstrap typeahead in datatables search

I'm trying to make the search box on a datatable have the bootstrap typeahead feature. I don't know how to access and manipulate the search box. Any ideas here?
AdamMasters
  • 355
  • 3
  • 19
4
votes
3 answers

Deleting a Row from JQuery Datatables

Hi I am deleting the row from the table using fnDeleteRow function but the problem is that it deletes the correct row for the first time only and than start deleting the next row instead of that for which I am pressing the delete button. here is my…
Najam-us-Saqib
  • 526
  • 3
  • 10
  • 23
4
votes
1 answer

DataTables warning (table id = 'table-filter'): Requested unknown parameter '0' from the data source for row 0 error in data tables

I have a table in which data is coming from a database. I am using data tables on that table. But the problem is when there is no row in the database, it displays alert DataTables warning (table id = 'table-filter'): Requested unknown parameter '0'…
Happy
  • 792
  • 2
  • 10
  • 32
4
votes
3 answers

Twitter bootstrap table pagination

I am currently working on tables in bootstrap. It is working fine and good. Currently I have a problem with pagination. I am trying to push the data dynamically into the table, once the data became too large the table is expanding downwards..How can…
Aravind Cheekkallur
  • 3,157
  • 6
  • 27
  • 41
4
votes
1 answer

how does jQuery.dataTable() hide rows?

I stumbled upon a strange behaviour while using jQuery + dataTables plugin. Let's say I have the following table: …
Gerrit-K
  • 1,298
  • 2
  • 15
  • 30
4
votes
1 answer

jQuery DataTables - add jquery generated element with events to a table cell

I'm using jQuery DataTables ( http://www.datatables.net ) to generate a table. I want to insert in certain cells(from a column) a jquery generated html element witch has some events attached to it. (onClick for example). I was thinking about mRender…
Doua Beri
  • 10,612
  • 18
  • 89
  • 138
4
votes
1 answer

afnFiltering is never called for datatable with ajax source

I'm trying to use global filtering on a datatable with an AJAX source as follows: var usertable = $("#userstable").dataTable({ "bProcessing": false, "bJQueryUI": false, "bAutoWidth": false, "bServerSide": true, "aLengthMenu":…
Ankit Khedekar
  • 924
  • 1
  • 7
  • 26
4
votes
3 answers

DataTables sort currency

Please help with live example, how to sort currency in format "34 566.00 ek." in DataTables script. Here is JSFiddle example: http://jsfiddle.net/HEDvf/643/ $('#example').dataTable({ "aoColumns": [ null, ], "aaSorting": [[ 0,…
user2481034
  • 87
  • 1
  • 2
  • 9
4
votes
1 answer

Django: Using DataTables

I want to introduce filtering and sorting functionality to my table using ajax. From what I found, DataTables seamed to be the best option. but, I can't seem to get it working! The first thing I tried was using it just how they have it set up with…
RuSs
  • 769
  • 2
  • 12
  • 27
4
votes
2 answers

Get Jquery data tables to sort on table that contains inputs

I've got a table that is a mixture of static
. To sort through and filter the data ive used the Jquery data tables plugin the only problem is that it won't sort the tags it just leaves them at…
sam
  • 9,486
  • 36
  • 109
  • 160
4
votes
1 answer

cannot read property 'ntr' of undefined

I am getting the error "cannot read property 'ntr' of undefined" when i perform mouseover function on a data-table when the data is not present. It works fine when the table is populated. The code is as follows: $('#example_table tbody…
user2680900
  • 171
  • 2
  • 11
col 0 col 1
and inputs (wrapped in td)