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

How to get the row number of selected row of jquery datatable

I am trying to get the row number from datatable and pass in to some update function.Some time it giving row number as [Object object] Here is my code: var table = $('#example').DataTable(); $('#example tbody').on( 'click', 'tr', function () { var…
chaya
  • 423
  • 3
  • 11
  • 19
4
votes
1 answer

Find a mongodb document using a partial _id string

I need to find either one or more documents in a collection that have a specific string in their _id field. this is proving to be a problem since the _id field is an object and not a string so i cant just regex it. for example lets say i have these…
Eyal Alsheich
  • 452
  • 4
  • 12
4
votes
1 answer

DataTables sorting cells containing only a glyphicon

I have a column that is pure glyphicons with no text. I'd like to make it sortable, right now clicking sort does nothing. I'd like to keep it to just icons and no text, is there anyway I can assign values for sorting purposes? Sample HTML for 1…
Andrew
  • 4,443
  • 5
  • 33
  • 75
4
votes
1 answer

dataTables JS Plugin responsive width overflows set div width

Using the DataTables plugin for displaying tabular data I found that when setting a percentage width on the tables container div the plugin was performing a width calculation and setting a pixel width on the table which was actually wider than the…
Rumpleteaser
  • 4,142
  • 6
  • 39
  • 52
4
votes
1 answer

DataTables row.add() function does not add all rows from the array

I'm working on a travel portal and using DataTables JS Plugin To Populate results. "search.results" is an array of JSON objects each containing search results, However, only first 30 are getting populated and the rest don't. console does not log any…
user3770135
  • 101
  • 3
4
votes
1 answer

Rstudio shiny renderDataTable headers multi line?

I have a renderDataTable table in Rstudio Shiny that I build with some columns I want to have the header going multi-line, so that a long header string takes a small amount of horizontal space. E.g.: My long header column is called…
719016
  • 9,922
  • 20
  • 85
  • 158
4
votes
1 answer

ColVis Selection Appears Behind Bootstrap Modal

I have the same issue as presented here: jQuery Datatables Column list rendering behind the jQuery Modal Dialog I have a DataTables table inside a Bootstrap modal window, and I am trying to use the ColVis extension to DataTables to make the columns…
Ellipsis17
  • 85
  • 1
  • 2
  • 10
4
votes
2 answers

How can I search in a specific column using the jQuery DataTables plugin?

I used the jquery dataTable plugin to show a table which contains (username, dates, and email). I want to disable the filtering/search for the username and email columns and enable just the search for the dates. when I click on the search field I'll…
Dev DOS
  • 1,018
  • 4
  • 18
  • 45
4
votes
1 answer

Datatable plugin - jquery - column re-sizing is adjusting relatively to other column. How to avoid that?

In data-table plugin, while I'm re-sizing the any of column with large size(width), I want to save the width of column and enable the horizontal scroll only when width is bigger, than some value(this value defined by me). Whereas now it is…
Krish
  • 489
  • 2
  • 8
  • 28
4
votes
1 answer

R, shiny: using ColVis DataTable plugin

I wish to use the ColVis plugin with DataTable in shiny. ColVis The plugin provides the user with a nice button/dropdown selection menu to control column visibility. In my latest attempt to get this working, I have: added dataTables.colVis.js to…
paul shannon
  • 355
  • 5
  • 15
4
votes
1 answer

datatables horizontal scroll bar to be shown on top instead of bottom

Datatables(JQuery plugin) has scrollx option, which when set to true will add scroll bar that will appear at the bottom of your table, is there an option to also display it at the top of your table.
GMoney
  • 205
  • 5
  • 11
4
votes
1 answer

jQuery DataTables fnGetData

I am using jQuery DataTables 1.10 plugin. In the earlier version, (1.9.4 plugin) I was able to get data from table like this: var iPos = oTable.fnGetPosition( this ); var aData = oTable.fnGetData( iPos ); Now, using the same code, I am getting the…
rosuandreimihai
  • 656
  • 3
  • 16
  • 39
4
votes
1 answer

DataTable get data of tr

i've built up a table with dataTable jQuery plugin. I am trying to get the td data of a tr element by clicking on that tr. I've read the documentation which says that i have to use "fnGetData", but when i try that, i get the error: TypeError:…
user3746259
  • 1,491
  • 2
  • 23
  • 46
4
votes
2 answers

datatables disable auto filter and added a button

I'm using datatables plugin and i would like to disable the auto filter on the table and instead put a search button when they've fully entered their text and are ready to search further. JSfiddle : $(document).ready(function() { …
user3734830
  • 53
  • 1
  • 4
4
votes
1 answer

jQuery DataTables - Child Rows and "Undefined is Not a Function"

I'm working to add child rows to a data table and am getting a "TypeError: undefined is not a function" for a line of code that works perfectly on a different table and page. Any ideas? HTML:
SteveSTL
  • 998
  • 3
  • 13
  • 21