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

Datatable : fixed width for selected columns only

I have a table, for which the number of columns are not fixed. However, the first 3 columns are always present. So, the following attribute would not work in my case(as the number of columns needs to be fixed in that approach) "aoColumns": [ …
ipradhansk
  • 352
  • 1
  • 10
  • 36
4
votes
1 answer

How to get the selected Table cell value in datatable

I am using jquery-2.0.3.min.js, bootstrap.min.js, jquery-ui-1.10.3.min.js, DataTables-1.9.4 with tabletools, datatables.net/blog/Twitter_Bootstrap_2 My View
vcs
  • 3,675
  • 4
  • 17
  • 15
4
votes
5 answers

The best way to hide empty columns in jquery dataTable

I lost two days searching for a good solution on how to hide empty columns in jQuery dataTables via javascript, so i came to my own solution coding a new plugin, i think this will help others do it very quickly, if you find this plugin usefull feel…
John Diaz
  • 341
  • 3
  • 13
4
votes
2 answers

JQuery DataTable Load the page of the selected row

I am using a JQuery DataTable. In my server side code, I am re-trieving the record id and passing it to my javascript function. My javascript function will look for the row as per the row id and then set the class to selected. function…
foop
  • 513
  • 1
  • 7
  • 16
4
votes
3 answers

DataTables.js Sort columns containing HTML links with integer text

I'm trying to sort columns in DataTables.js that contain HTML anchor tags. The text within the anchor tag is an integer, like 123. I want to sort the columns numerically. In the documentation examples, there is DataTables HTML…
Adam
  • 1,932
  • 2
  • 32
  • 57
4
votes
2 answers

How to stop a parent div expanding vertically when child div becomes visible

I have a parent div that has a height set on it. There are child divs inside of it with initial visibility turned off. When I make it visible, the parent div expands vertically. I dont want that. Background: I'm using DataTables, with the scroller…
user2577751
  • 91
  • 2
  • 5
I read the documentation at http://datatables.net/examples/plug-ins/range_filtering.html for filtering by a range, but I don't quite understand how to filter items by a row's class. I want to have a several buttons that when clicked, filter the…
Derek
  • 9,773
  • 7
  • 29
  • 34
4
votes
4 answers

How to get filtering params for jquery datatable(datatables.net)?

I'm using jquery DataTables (from datatables.net) with server-side processing and ColumnFiltering add-on. I need to add a callback which will compute subtotals based on filtered data. In order to achieve this I want to make a separate ajax call. How…
Alex
  • 387
  • 4
  • 16
4
votes
4 answers

datatables jquery - alternate colors for the rows

I have used datatables jquery in my application. When I used datatables jquery to set alternate colors for my rows, I faced a issue. That is, in a table 2nd,3rd,4th,5th n 6th row are all displayed in same color and after that colors are displayed…
kishore
  • 1,587
  • 4
  • 15
  • 17
4
votes
2 answers

Passing arguments to sAjaxSource in jQuery datatables

I am working with CodeIgniter and I have the following problem. I have a controller function in details.php which takes an argument: function details($id) { $this->datatables ->select('product_id, original_amount, quantity') …
Rishi Reddy
  • 123
  • 1
  • 2
  • 10
4
votes
1 answer

JQuery Autocomplete #combobox not working with jquery DataTables

Requirement : I need editable drop down in my application similar to the one in the given here. In my existing application I am using jQuery Data table within this table I need one of the column to be editable drop down. For this I Googled it and…
Sangamesh
  • 89
  • 1
  • 5
4
votes
3 answers

JQUERY DataTable -- TypeError: k is undefined - Dynamically forming Table with MVC

Am trying JQUERY DataTable with MVC. First thing am trying to do is trying to set up the base. Am trying to get the column and Datavalues Dynamically. am using fnServerData with sAjaxSource. Am having a breakpoint in my controller file to see if…
user2067567
  • 3,695
  • 15
  • 49
  • 77
4
votes
4 answers

MVC 4 Jquery DataTable Paging Loses Model Reference

This is the view I have for my table. When I post back to my controller, my model will give me the items in ListUsers and set the properties of "InGroup" = true (if checked), and the UserId that it was checked for. This works completely fine. …
foop
  • 513
  • 1
  • 7
  • 16
4
votes
4 answers

Trouble with DataTables

I am having trouble using the jQuery library DataTables. I have followed their documentation, and have run into an odd problem. To begin with, I was trying to use the FixedColumn feature, but even the example that they offer doesn't run (at least…
Crash
  • 219
  • 6
  • 16
4
votes
3 answers

jQuery datatables hide thead

i want to hide datatable thead if table dont have any data. oTable_topics =$('#showTopics').dataTable({ "bLengthChange": false, "bStateSave": true, "iDisplayLength": 12, "bScrollCollapse": true, …
user2388554