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
2 answers

Why is tableTools making multiple calls to the same SWF file?

I happened to notice in my application that the copy_csv_xls_pdf.swf is getting called three times when datatables/tabletools are invoked. I put together a jsfiddle which (sometimes) illustrates the issue: The same behavior can be observed from the…
Jeromy French
  • 11,812
  • 19
  • 76
  • 129
4
votes
1 answer

R Shiny picking and storing favorites from checked dataTables

Background I'm trying to create a multi-table Shiny app in which you can pick your favorite rows in each of several tables, through checkboxes. These should then be stored across sessions, and rendered in an additional "Favorites" table.…
vasilios
  • 51
  • 1
  • 5
4
votes
1 answer

Datatables jQuery $(document).ready not working and being replaced by numbers

I'm trying to initiate a DataTables instance with the following code... But when I access the HTML…
Emiliano
  • 83
  • 6
4
votes
1 answer

How to show all page numbers in jQuery DataTable pagination

How to show all page numbers in jQuery datatable pagination? For example instead of 1 2 3 ... 10, I want 1 2 3 4 5 6 7 8 9 10. My code now is this: $('.paginated-table').dataTable({ "lengthMenu": [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]], …
GhitaB
  • 3,275
  • 3
  • 33
  • 62
4
votes
3 answers

jQuery dataTables sorting is not working for dd-mm-yyyy format

In my project I want to sort date which is in dd-mm-yyyy format. I tried like this below jQuery.extend(jQuery.fn.dataTableExt.oSort, { "date-uk-pre": function(a) { var ukDatea = a.split('-'); return (ukDatea[2] + ukDatea[1] +…
Anju
  • 502
  • 1
  • 6
  • 20
4
votes
1 answer

DataTables TypeError: ...draw is not a function

I'm attempting to use a custom input for searching/filtering a jQuery Datatables table. I'm using jQUery 2.1.1 and DataTables 1.10.4. My code is pretty simple, and mirrors what's in the API docs: var table = $('#pList').DataTable({ …
dbrosier
  • 330
  • 4
  • 11
4
votes
2 answers

How to use different values for sort and display in DataTables 1.10

I've upgraded to DataTables 1.10 and am having trouble using column.data or column.render to use different values for sort and display. The data looks like: [ { "title":"Overview Report: (2014-07-12 11:49 - 2014-07-12 23:49)", …
Scott Glew
  • 158
  • 1
  • 7
4
votes
3 answers

How to disable zebra rows on jquery table

I'm using basic setup this.$el.find('#data-provider-table').dataTable(); but table comes with stripes by default (as in http://www.datatables.net/examples/styling/stripe.html example). I want to disable them, but have no idea how to do that. Please…
Petro Semeniuk
  • 6,970
  • 10
  • 42
  • 65
4
votes
0 answers

Datatables and tabletools: How to export selected and sorted data to pdf, csv,

I spend all day looking for a solution on the internet, where need to export data after I have them sorted and selected rows. I use: dataTables 1.10.3 tabletools 2.2.3 In the code, I put the following: $(function(){ var table =…
Salines
  • 5,674
  • 3
  • 25
  • 50
4
votes
2 answers

How to refresh Datatable data from js array of objects

I'm using the jquery DataTables plugin to display an array of objects. I would like to clear the table and redraw using the changed data. However, the only way I've been able to do that so far is to destroy the table and reinitialize. I'd like to…
Gregism
  • 392
  • 5
  • 11
4
votes
3 answers

Columndefs not working Datatables

I am trying to work with columndefs to add custom colors to a column. But i started with a simple scenario just to get columndefs to work. But i am unable to do so. This is my CoffeeScript file. jQuery -> $('#clients').dataTable …
user2611745
  • 61
  • 1
  • 1
  • 7
4
votes
3 answers

statesave not working with datatables when rows are added dynamically

I am using DataTables and I initialize the table with $(document).ready(function() { $('#example').dataTable( { stateSave: true } ); } ); I populate my table dynamically using $('#example').row.add(...) When I reload or revisit my…
user3871397
  • 81
  • 1
  • 2
4
votes
1 answer

store dataset filtered using DataTables in Shiny in app

To perhaps save a few people a minute or two ... this question is about DataTables in a Shiny app (http://shiny.rstudio.com/articles/datatables.html) and not Data.Table I would like to access the index of rows available in DataTables in Shiny. I do…
Vincent
  • 5,063
  • 3
  • 28
  • 39
4
votes
1 answer

Summing a filtered column in DataTables

I'm trying to sum the results of filtered columns in DataTables. I've viewed the questions asked on their website and folks have had success using this method. However, similar code for me produces 'Uncaught TypeError: undefined is not a…
Isaac Askew
  • 1,281
  • 2
  • 17
  • 30
4
votes
2 answers

How to disable a search/filter on a specific column on a datatable?

My datatable has 5 columns and I need to disable filtering for the 3rd, 4th and last column. please help!!! this is the javascript: