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

jQuery DataTables fixedColumns remove fixed columns dynamically

I'm using fixedColumns plugin for my DataTables component. And I want to allow users to toggle fixed columns from the table header. Creating the fixed columns is straign forward: this.table.fixedColumns = new $.fn.dataTable.FixedColumns(this.table,…
Brock
  • 1,635
  • 2
  • 18
  • 27
4
votes
3 answers

JQuery Datatables click event not working for pages except 1

I am using JQuery Datatable for my application. I have a simple code which displays all my clients and a script which fires on the click of table row. Now, the problem is, this works fine for the first page, however, for all the other pages click…
Chintan Parekh
  • 1,101
  • 1
  • 12
  • 31
4
votes
1 answer

JQuery DataTables - Refresh Table Data After Post - ColdFusion

I'm posting a very simple example of what I want to do because it's easier to explain that way. I have a datatable populated with a cfquery. When you double click on a table row, the JQuery script will send the RecordID to an action page as a url…
madvora
  • 1,717
  • 7
  • 34
  • 49
4
votes
2 answers

How to right align columns of DataTable in R Shiny?

From this post I gather we should define an alignRight CSS class with the desired alignment: # ui.R sidebarLayout(..., mainPanel( tags$head( tags$style(".alignRight { align: right; }", media = "all", type = "text/css") …
mchen
  • 9,808
  • 17
  • 72
  • 125
4
votes
1 answer

ng-click is not working with AngularJS and dataTables

I am using jQuery DataTable directive with angularJS which is working fine. The problem I am facing is adding javascript function to "TR" dynamically with "ng-click" which is not working. It seem's like dynamically added elements are not recognized…
Salman Raza
  • 320
  • 1
  • 8
  • 23
4
votes
3 answers

jquery Mark the new added row in datatable

I have a existing datatable in my html page, and I try adding new row using fnAddData var addId = vandropDatatable.fnAddData(["1", "2"]); How can I findout the new added row to add some class for it (for example addClass("New_item") )
VinhNT
  • 1,091
  • 8
  • 13
4
votes
3 answers

Jquery Datatables expand row and get detail via Ajax

Is it possible to get the detail for each row through Ajax? I found a starting point here: http://datatables.net/release-datatables/examples/api/row_details.html but it doesn't use ajax. I'm thinking about modifying fnFormatDetails() function and…
Yohanes Pradono
  • 294
  • 1
  • 4
  • 16
4
votes
1 answer

DataTables.Net Bootstrap 3 Pagination Missing First Last buttons

I am following Allan's this plugins for integrating DataTables with bootstrap. Have make a good progress so far and only thing I am missing is first and last buttons in the pagination (currently I have Next/Previous buttons, but I need…
RasikaSam
  • 5,363
  • 6
  • 28
  • 36
4
votes
2 answers

Datatables modify filter html

I'm using the jQuery Datatables plugin and I would like to customize some of the generated HTML for the filter. Specifically, they generate the following HTML:
4
votes
1 answer

jQuery Datatables show page numbers at top

I am using jQuery Datatables with pagination numbers at the bottom of the table. However, I would like to move it to the top since when the page numbers are changes, because of the amount of data (also iDisplayLength set as 100), user requires to…
user2675939
  • 361
  • 2
  • 6
  • 22
4
votes
6 answers

Jquery DataTables plugin - sAjaxSource

I get my data from the asp.net web service and I was wondering whether there is a way to pass on that data (in json formar straight from the web service) into the DataTables object. I would like to do something like: $(document).ready(function() { …
sarsnake
  • 26,667
  • 58
  • 180
  • 286
4
votes
1 answer

How can I set DataTables row callbacks in a Shiny R application?

In rCharts, one can set JS callbacks of DataTables using a special string notation: #! function(par) {...} !#. For example, let's look into the following R code: #JS callback to truncate long strings in table cells and add a tooltip callback =…
gkcn
  • 1,360
  • 1
  • 12
  • 23
4
votes
1 answer

Programmatically Change the DisplayLength of DataTables

I have been using dataTables for a while and its a solid tool. There is a option for setting the initial display length, iDisplayLength. I would like to change the display length programmatically after the table has initialized. My custom data…
Binary Alchemist
  • 1,600
  • 1
  • 13
  • 28
4
votes
3 answers

Dynamically load data from server to "select" type input fields in datatables

I have a PHP code that is being called by the function loader that is only triggered on onInitCreate event in datatable. What I want to do is that when the user clicks the add button it must load the faculty Names in the select field. I've already…
Harvey
  • 399
  • 4
  • 15
  • 31
4
votes
3 answers

How to convert HTML table into jQuery DataTable?

I've tried this:
user2898127