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
61
votes
7 answers

jQuery datatables add class to tr

I am using jQuery and datatables. I want to add a class to the TR element of a particular row. I know how to find the row. The console.dir(row); shows the row object and that starts with a tr element. I can't get the jQuery selector to do…
7 Reeds
  • 2,419
  • 3
  • 32
  • 64
59
votes
7 answers

How do I add button on each row in datatable?

I am newbie for DataTables. I want to add button on each row for edit and delete(like below image) I have tried with code: Test.cfm …
Sameek Mishra
  • 9,174
  • 31
  • 92
  • 118
58
votes
23 answers

DataTables fixed headers misaligned with columns in wide tables

Problem When using the sScrollX, sScrollXInner and/or sScrollY to achieve a fixed header table with its inner content scrolling, the headers of the table go out of alignment with the rest of the body in Chrome and IE. Firefox, on the other hand,…
bPratik
  • 6,894
  • 4
  • 36
  • 67
57
votes
9 answers

jquery datatables default sort

I am trying to set the default sort to the second column in my jquery datatable. It by default sorts by index 0. I am using the "aaSorting": [[ 1, "asc" ]] syntax but it highlights the column which I don't want on initial load. How can I set the…
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
56
votes
5 answers

table.row is not a function

I am trying to implement row details in my datatables just like this example. When I click on the show more image of my table, I get an error in my firebug console saying: TypeError: oTable.row is not a function var row = oTable.row(tr); Here is…
MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125
54
votes
10 answers

call a function in success of datatable ajax call

Is that possible to invoke a javascript function in success of datatable ajax call. Here is the code am trying to use, var oTable = $('#app-config').dataTable( { "bAutoWidth": false, …
rajan.tsm
  • 541
  • 1
  • 4
  • 4
54
votes
5 answers

Giving custom classes to each TD for styling - Datatables & jQuery

I'm using datatables for displaying server-side data in tables. I can't target and style individual cells (
UserID ) though. I search a bit and found it might be possible with: "fnRowCallback": function( nRow, aData, iDisplayIndex ) { .... } ...…
eozzy
  • 66,048
  • 104
  • 272
  • 428
53
votes
15 answers

dataTables Export to Excel button is not showing

I have a problem in jquery dataTables. The "Export to Excel" is not showing in iPad and mobile devices. It is showing in desktop. Other buttons like copy, csv and pdf are showing in iPad and desktop. Here is my code…
Ninju
  • 2,522
  • 2
  • 15
  • 21
52
votes
12 answers

Detect page change on DataTable

With DataTable I can order, list, do pagination but I want to detect when the pagination changes, I've seen the API but the only one I can do is change the page but no detect this change.
Felix
  • 3,058
  • 6
  • 43
  • 53
52
votes
8 answers

table.columns is not a function in datatable.js