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
1 answer

Correct way to redraw a DataTable? Getting errors: "no method 'fnDraw'" and "cannot read property 'oFeatures'"

I have inherited the following code: // Show / Hide table rows from checkboxes $("table.data#report-table .warning").toggle($("#warning_checkbox").is(":checked")); $("#warning_checkbox").click(function() { $("table.data#report-table…
rwb
  • 4,309
  • 8
  • 36
  • 59
4
votes
1 answer

DataTables Sorting html table on the basis of TD Attribute value

I am using the DataTables jquery library to display simple HTML table markup, i.e. not using Ajax or JSON. It is all working nicely except that I have some columns where I would like to sort on the raw data, not on the formatted data that is…
Bob Mackay
  • 41
  • 1
  • 2
4
votes
3 answers

DataTables, select rows and pass back ID for delete

first time posting here but i really need help. Been working on this little project for a while and am finding Datatables to be next to useless but im being told i must use it....anyway Ive got it displaying our table from an ajax call to our SQL…
user2069834
  • 83
  • 1
  • 1
  • 7
4
votes
1 answer

How to see fixed columns on print view, using dataTables with FixedColumns and TableTools

I'm using DataTables with FixedColumns and TableTools extras among others. When I click Print button for seeing the print preview, the fixed columns are not shown, but PDF and Excel functions prints all the columns. Here you can see a live…
David
  • 4,336
  • 2
  • 23
  • 31
4
votes
1 answer

delete all datatables using jQuery

so, I am using datatables along with jQuery, and am a bit stumped as to why this is not working. My HTML looks like this: …
Kreg
  • 647
  • 1
  • 6
  • 17
4
votes
1 answer

datatables sInfo changing text when table empty

Alright, I know I can change the text generally speaking as such: "oLanguage": { "sInfo": 'Showing _END_ Sources.', "sEmptyTable": "No Sources found currently, please add at least one.", } the sInfo Property changes…
chris
  • 36,115
  • 52
  • 143
  • 252
4
votes
1 answer

How to add a row ID to each row?

I am trying to add row ids to tr using jquery datatables. I even tried the example http://datatables.net/release-datatables/examples/server_side/ids.html but didn't seem to work, I used their same JSON file. Any help would be greatly appreciated. It…
user244394
  • 13,168
  • 24
  • 81
  • 138
4
votes
1 answer

Dynamically get column names in $aColumns arrary in datatables

First I'll mention what I am trying to achieve. I am using CodeIgniter framework of PHP. I have 5 tables in my database and I want to display them in Datatables format on a button click on the display page. I am using server side processing php as…
SilentAssassin
  • 468
  • 1
  • 9
  • 27
4
votes
1 answer

Datatables: Uncaught TypeError: Cannot read property 'length' of undefined

I'm attempting to use an ajax source with Datatables, and I've run into some errors in doing. Previously Ajax was not being used with Datatables, and they were working fine, but upon trying to use Ajax and JSON I have some errors. The error I am…
ComputerLocus
  • 3,448
  • 10
  • 47
  • 96
4
votes
1 answer

TypeError: jQuery(...).dataTable is not a function in Grails

I'm trying to install jquery datatable on grails 2.1 with no luck until now. I installed JQuery, JQuery-ui and jquery-datatable plugins. added the following code to main.gsp:
Feras Odeh
  • 9,136
  • 20
  • 77
  • 121
4
votes
4 answers

Datatables get row Data without clicking on it

I'm using DataTables to show a list of messages. I need a way to get a specific row of data based off an id being passed to the page on the Query string. ex. www.webpage.com?id=2 I already have the id in a jQuery variable. Now I just need to access…
Silverwulf
  • 109
  • 1
  • 2
  • 10
4
votes
2 answers

Showing custom message in jquery datatable while loading data?

I have below code in jsp to create a dataTable. I am using bProcessing as true which displays the 'processing' indicator till i get the data from the server. I want to show the message as "loading data.." instead of 'processing'. I tried using…
emilly
  • 10,060
  • 33
  • 97
  • 172
4
votes
1 answer

Altering jquery datatables aoColumns

I am using uptil now 3 datatables in jquery-ui tabs. i prefer to keep them all in background and really use 3 tables. The data comes via ajax in arrays of objects (is used in that format also by other presenters). However, since the number and type…
h0ru5
  • 517
  • 2
  • 7
  • 11
4
votes
1 answer

PJAX / Back-Button destroys Datatables

In our Rails 3.2 App with rack-pjax enabled appears the following Problem: You click on a link, a page with datatable in it loads trough pjax. Everything is fine. You click on antoher link the page "whatever" loads. You hit the back-button the…
patrickkeller
  • 1,236
  • 2
  • 11
  • 20
4
votes
3 answers

Determining what column/row is clicked by a user

Using JQuery, I need to know if the User clicked on the link or third column, and need to get the value of the variable in the first column. How do I do this? My html:
Partitions
user1789239
  • 87
  • 1
  • 6
1 2 3
99
100