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
405
votes
22 answers

Datatables: Cannot read property 'mData' of undefined

I have an issue with Datatables. I also went through this link which didn't yield any results. I have included all the prerequisites where I'm parsing data directly into the DOM. Script $(document).ready(function() { $('.viewCentricPage…
Thriveni
  • 4,183
  • 2
  • 14
  • 12
321
votes
23 answers

How can I remove the search bar and footer added by the jQuery DataTables plugin?

I am using jQuery DataTables. I want to remove the search bar and footer (showing how many rows there are visible) that is added to the table by default. I just want to use this plugin for sorting, basically. Can this be done?
leora
  • 188,729
  • 360
  • 878
  • 1,366
294
votes
3 answers

Is there a way to disable initial sorting for jquery DataTables?

I'm using the jquery DataTables plugin. From their documentation: If sorting is enabled, then DataTables will perform a first pass sort on initialisation. You can define which column(s) the sort is performed upon, and the sorting direction, with…
smoak
  • 14,554
  • 6
  • 33
  • 33
182
votes
16 answers

DataTables: Cannot read property style of undefined

I am getting this error with the following: jquery.dataTables.js:4089 Uncaught TypeError: Cannot read property 'style' of undefined(…) _fnCalculateColumnWidths @ jquery.dataTables.js:4089 _fnInitialise @ jquery.dataTables.js:3216 (anonymous…
Rookie
  • 5,179
  • 13
  • 41
  • 65
164
votes
23 answers

Disable sorting for a particular column in jQuery DataTables

I am using the jQuery DataTables plugin to sort the table fields. My question is: how do I disable sorting for a particular column? I have tried with the following code, but it did not work: "aoColumns": [ { "bSearchable": false }, null ] I…
usman
  • 1,947
  • 4
  • 19
  • 19
139
votes
18 answers

TypeError: $(...).DataTable is not a function

I am trying to work with jQuery's Datatable JS for my project from this link. I downloaded the complete library from the same source. All the examples given in the package seem to work fine, but when I try to incorporate them in my WebForms,the…
Abhishek Ghosh
  • 2,593
  • 3
  • 27
  • 60
135
votes
12 answers

Datatables - Search Box outside datatable

I'm using DataTables (datatables.net) and I would like my search box to be outside of the table (for example in my header div). Is this possible ?
Athanasios Emmanouilidis
  • 2,084
  • 3
  • 18
  • 30
130
votes
5 answers

How to hide "Showing 1 of N Entries" with the dataTables.js library

How do you remove the "Showing 1 of N entries" line of text on a dataTable (that is when using the javascript library dataTables? I think I was looking for something along these lines... $('#example').dataTable({ "showNEntries" : false …
nickL
  • 1,536
  • 2
  • 10
  • 15
124
votes
15 answers

JQuery Datatables : Cannot read property 'aDataSort' of undefined

I created this fiddle to and it works well as per my requirements: Fiddle However, when I use the same in my application I get an error in the browser console saying Cannot read property 'aDataSort' of undefined In my application, the javascript…
swateek
  • 6,735
  • 8
  • 34
  • 48
120
votes
6 answers

How to manually update datatables table with new JSON data

I am using plugin jQuery datatables and load my data which I have loaded in DOM at the bottom of page and initiates plugin in this way: var myData = [ { "id": 1, "first_name": "John", "last_name": "Doe" …
Indy
  • 4,838
  • 7
  • 24
  • 35
117
votes
8 answers

how to remove pagination in datatable

I have used Datatables in grid but need not pagination. There is a list of orders in one page and I show them in a Datatable grid but in bottom I do not want to show pagination. Is there any way to remove or hide pagination from the data table by…
Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
115
votes
26 answers

How to reload/refresh jQuery dataTable?

I am trying to implement functionality whereby clicking a button on the screen will cause my jQuery dataTable to refresh (as the server-side data source may have changed since the dataTable was created). Here's what I…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
110
votes
39 answers

datatable jquery - table header width not aligned with body width

I am using jQuery datatables. When running the application, the header width is not aligned with the body width. But when I click on the header, it is getting aligned with the body width but even then there is some light misalignment. This problem…
kishore
  • 1,587
  • 4
  • 15
  • 17
107
votes
26 answers

jQuery DataTables: control table width

I have a problem controlling the width of a table using the jQuery DataTables plugin. The table is supposed to be 100% of the container width, but ends up being an arbitrary width, rather less than the container width. Suggestions appreciated The…
John Mac
  • 2,530
  • 4
  • 24
  • 30
106
votes
31 answers

Datatable date sorting dd/mm/yyyy issue

I am using a Jquery plugin called datatables Its fantastic, however I cannot get the dates to sort correctly according to the dd/mm/yyyy format. I have looked at their support formats but none of these fixes seem to work. Can anybody here help me…
jaget
  • 2,149
  • 6
  • 21
  • 29
1
2 3
99 100