1. Components
  2. DataTables

Third-Party Plugins

Tailwind CSS Datatables

Enhance HTML tables with Tailwind CSS Datatables, featuring search, paging, and sorting. Improve user experience with efficient data navigation and management.

Requires Additional Installation

Note that this component requires the use of the third-party DataTables.net and jQuery libraries.

Requires JS

Note that this component requires the use of Preline UI's Datatables plugin, else you can skip this message if you are already using Preline UI as a package.

How to use

  1. Install jQuery.

    Install jquery via npm

    npm i jquery
  2. Install Datatbles.net.

    Install datatables.net-dt via npm

    npm i datatables.net-dt
  3. Add additional CSS.

    Add CSS for hiding some default elements:

                        
                          .dt-layout-row:has(.dt-search),
                          .dt-layout-row:has(.dt-length),
                          .dt-layout-row:has(.dt-paging) {
                            display: none !important;
                          }
                        
                      
  4. Add the Datatables JavaScript

    Include the JavaScript <script> near the end of your </body> tag:

                        
                      
  5. Add additional settings to activate the function of highlighting text selected using cmd+a in text fields. By default, Datatable blocks this functionality.

    Include the JavaScript after initializing the Datatables:

                        
                          window.addEventListener('load', () => {
                            ...
    
                            const inputs = document.querySelectorAll('.dt-container thead input');
    
                            inputs.forEach((input) => {
                              input.addEventListener('keydown', function (evt) {
                                if ((evt.metaKey || evt.ctrlKey) && evt.key === 'a') this.select();
                              });
                            });
                          });
                        
                      

Example

Using the most basic table markup, here's how tables look.

All the examples are responsive - tables allow tables to be scrolled horizontally with ease.

Name
Age
Address
Action
Christina Bersh 45 4222 River Rd, Columbus
David Harrison 27 2952 S Peoria Ave, Tulsa
Anne Richard 31 255 Dock Ln, New Tazewell
Samia Kartoon 45 4970 Park Ave W, Ohio
David Harrison 27 4222 River Rd, Columbus
Brian Halligan 31 2952 S Peoria Ave, Tulsa
Andy Clerk 45 1818 H St NW, Washington
Bart Simpson 27 3 Grace Dr, New Mexico
Camila Welters 45 4531 W Saile Dr, North Dakota
Oliver Schevich 27 2126 N Eagle, Meridian, Illinois
Inna Ivy 31 3817 Beryl Rd, Nebraska
Jessica Williams 27 4807 3rd Ave, New Hampshire
James Collins 31 Melbourne No. 1 Lake Park
Costa Quinn 27 New York No. 1 Lake Park
Jim Green 27 LA No. 1 Lake Park
Joe Black 31 Sidney No. 1 Lake Park
Isabella Cherry 27 4222 River Rd, Columbus
Alex Tacker 31 2952 S Peoria Ave, Tulsa
Endy Ruiz 45 1818 H St NW, Washington
Jack Li 27 3 Grace Dr, New Mexico

Scrollable table body (tbody)

Tbody makes a scroll.

Name
Age
Address
Action
Christina Bersh 45 4222 River Rd, Columbus
David Harrison 27 2952 S Peoria Ave, Tulsa
Anne Richard 31 255 Dock Ln, New Tazewell
Samia Kartoon 45 4970 Park Ave W, Ohio
David Harrison 27 4222 River Rd, Columbus
Brian Halligan 31 2952 S Peoria Ave, Tulsa
Andy Clerk 45 1818 H St NW, Washington
Bart Simpson 27 3 Grace Dr, New Mexico
Camila Welters 45 4531 W Saile Dr, North Dakota
Oliver Schevich 27 2126 N Eagle, Meridian, Illinois
Inna Ivy 31 3817 Beryl Rd, Nebraska
Jessica Williams 27 4807 3rd Ave, New Hampshire
James Collins 31 Melbourne No. 1 Lake Park
Costa Quinn 27 New York No. 1 Lake Park
Jim Green 27 LA No. 1 Lake Park
Joe Black 31 Sidney No. 1 Lake Park
Isabella Cherry 27 4222 River Rd, Columbus
Alex Tacker 31 2952 S Peoria Ave, Tulsa
Endy Ruiz 45 1818 H St NW, Washington
Jack Li 27 3 Grace Dr, New Mexico

Selection

Rows can be selectable by making first column as a selectable column.

Name
Age
Address
Action
Christina Bersh 45 4222 River Rd, Columbus
David Harrison 27 2952 S Peoria Ave, Tulsa
Anne Richard 31 255 Dock Ln, New Tazewell
Samia Kartoon 45 4970 Park Ave W, Ohio
David Harrison 27 4222 River Rd, Columbus
Brian Halligan 31 2952 S Peoria Ave, Tulsa
Andy Clerk 45 1818 H St NW, Washington
Bart Simpson 27 3 Grace Dr, New Mexico
Camila Welters 45 4531 W Saile Dr, North Dakota
Oliver Schevich 27 2126 N Eagle, Meridian, Illinois
Inna Ivy 31 3817 Beryl Rd, Nebraska
Jessica Williams 27 4807 3rd Ave, New Hampshire
James Collins 31 Melbourne No. 1 Lake Park
Costa Quinn 27 New York No. 1 Lake Park
Jim Green 27 LA No. 1 Lake Park
Joe Black 31 Sidney No. 1 Lake Park
Isabella Cherry 27 4222 River Rd, Columbus
Alex Tacker 31 2952 S Peoria Ave, Tulsa
Endy Ruiz 45 1818 H St NW, Washington
Jack Li 27 3 Grace Dr, New Mexico

Search input

Search is used for making dropdown items searchable.

Name
Age
Address
Action
Christina Bersh 45 4222 River Rd, Columbus
David Harrison 27 2952 S Peoria Ave, Tulsa
Anne Richard 31 255 Dock Ln, New Tazewell
Samia Kartoon 45 4970 Park Ave W, Ohio
David Harrison 27 4222 River Rd, Columbus
Brian Halligan 31 2952 S Peoria Ave, Tulsa
Andy Clerk 45 1818 H St NW, Washington
Bart Simpson 27 3 Grace Dr, New Mexico
Camila Welters 45 4531 W Saile Dr, North Dakota
Oliver Schevich 27 2126 N Eagle, Meridian, Illinois
Inna Ivy 31 3817 Beryl Rd, Nebraska
Jessica Williams 27 4807 3rd Ave, New Hampshire
James Collins 31 Melbourne No. 1 Lake Park
Costa Quinn 27 New York No. 1 Lake Park
Jim Green 27 LA No. 1 Lake Park
Joe Black 31 Sidney No. 1 Lake Park
Isabella Cherry 27 4222 River Rd, Columbus
Alex Tacker 31 2952 S Peoria Ave, Tulsa
Endy Ruiz 45 1818 H St NW, Washington
Jack Li 27 3 Grace Dr, New Mexico

Filter

This example shows how to filter a DataTable.

Name
Age
Address
Action
Christina Bersh 45 4222 River Rd, Columbus
David Harrison 27 2952 S Peoria Ave, Tulsa
Anne Richard 31 255 Dock Ln, New Tazewell
Samia Kartoon 45 4970 Park Ave W, Ohio
David Harrison 27 4222 River Rd, Columbus
Brian Halligan 31 2952 S Peoria Ave, Tulsa
Andy Clerk 45 1818 H St NW, Washington
Bart Simpson 27 3 Grace Dr, New Mexico
Camila Welters 45 4531 W Saile Dr, North Dakota
Oliver Schevich 27 2126 N Eagle, Meridian, Illinois
Inna Ivy 31 3817 Beryl Rd, Nebraska
Jessica Williams 27 4807 3rd Ave, New Hampshire
James Collins 31 Melbourne No. 1 Lake Park
Costa Quinn 27 New York No. 1 Lake Park
Jim Green 27 LA No. 1 Lake Park
Joe Black 31 Sidney No. 1 Lake Park
Isabella Cherry 27 4222 River Rd, Columbus
Alex Tacker 31 2952 S Peoria Ave, Tulsa
Endy Ruiz 45 1818 H St NW, Washington
Jack Li 27 3 Grace Dr, New Mexico
Showing to of users

Column Filter

This example shows how to filter a DataTable column.

Age
Address
Action
Christina Bersh 45 4222 River Rd, Columbus
David Harrison 27 2952 S Peoria Ave, Tulsa
Anne Richard 31 255 Dock Ln, New Tazewell
Samia Kartoon 45 4970 Park Ave W, Ohio
David Harrison 27 4222 River Rd, Columbus
Brian Halligan 31 2952 S Peoria Ave, Tulsa
Andy Clerk 45 1818 H St NW, Washington
Bart Simpson 27 3 Grace Dr, New Mexico
Camila Welters 45 4531 W Saile Dr, North Dakota
Oliver Schevich 27 2126 N Eagle, Meridian, Illinois
Inna Ivy 31 3817 Beryl Rd, Nebraska
Jessica Williams 27 4807 3rd Ave, New Hampshire
James Collins 31 Melbourne No. 1 Lake Park
Costa Quinn 27 New York No. 1 Lake Park
Jim Green 27 LA No. 1 Lake Park
Joe Black 31 Sidney No. 1 Lake Park
Isabella Cherry 27 4222 River Rd, Columbus
Alex Tacker 31 2952 S Peoria Ave, Tulsa
Endy Ruiz 45 1818 H St NW, Washington
Jack Li 27 3 Grace Dr, New Mexico
Showing to of users

Hidden Columns

This example shows how to add "hidden column" functionality.

Name
Age
Address
Action
Christina Bersh 45 4222 River Rd, Columbus
David Harrison 27 2952 S Peoria Ave, Tulsa
Anne Richard 31 255 Dock Ln, New Tazewell
Samia Kartoon 45 4970 Park Ave W, Ohio
David Harrison 27 4222 River Rd, Columbus
Brian Halligan 31 2952 S Peoria Ave, Tulsa
Andy Clerk 45 1818 H St NW, Washington
Bart Simpson 27 3 Grace Dr, New Mexico
Camila Welters 45 4531 W Saile Dr, North Dakota
Oliver Schevich 27 2126 N Eagle, Meridian, Illinois
Inna Ivy 31 3817 Beryl Rd, Nebraska
Jessica Williams 27 4807 3rd Ave, New Hampshire
James Collins 31 Melbourne No. 1 Lake Park
Costa Quinn 27 New York No. 1 Lake Park
Jim Green 27 LA No. 1 Lake Park
Joe Black 31 Sidney No. 1 Lake Park
Isabella Cherry 27 4222 River Rd, Columbus
Alex Tacker 31 2952 S Peoria Ave, Tulsa
Endy Ruiz 45 1818 H St NW, Washington
Jack Li 27 3 Grace Dr, New Mexico
Showing to of users

Fixed header

Header is fixed until the end of the table.

  1. Install Datatables.net-fixedheader.

    Install datatables.net-fixedheader via npm

    npm i datatables.net-fixedheader
  2. Add Datatables.net-fixedheader to the page.

    Include the JavaScript <script> near the end of your </body> tag:

    <script src="./node_modules/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
Name
Age
Address
Action
Christina Bersh 45 4222 River Rd, Columbus
David Harrison 27 2952 S Peoria Ave, Tulsa
Anne Richard 31 255 Dock Ln, New Tazewell
Samia Kartoon 45 4970 Park Ave W, Ohio
David Harrison 27 4222 River Rd, Columbus
Brian Halligan 31 2952 S Peoria Ave, Tulsa
Andy Clerk 45 1818 H St NW, Washington
Bart Simpson 27 3 Grace Dr, New Mexico
Camila Welters 45 4531 W Saile Dr, North Dakota
Oliver Schevich 27 2126 N Eagle, Meridian, Illinois
Inna Ivy 31 3817 Beryl Rd, Nebraska
Jessica Williams 27 4807 3rd Ave, New Hampshire
James Collins 31 Melbourne No. 1 Lake Park
Costa Quinn 27 New York No. 1 Lake Park
Jim Green 27 LA No. 1 Lake Park
Joe Black 31 Sidney No. 1 Lake Park
Isabella Cherry 27 4222 River Rd, Columbus
Alex Tacker 31 2952 S Peoria Ave, Tulsa
Endy Ruiz 45 1818 H St NW, Washington
Jack Li 27 3 Grace Dr, New Mexico

Column Actions

This example shows how actions can be added to DataTable columns.

  1. Install Datatables.net-colreorder.

    Install datatables.net-colreorder-dt via npm

    npm i datatables.net-colreorder-dt
  2. Add Datatables.net-colreorder to the page.

    Include the JavaScript <script> near the end of your </body> tag:

    <script src="./node_modules/datatables.net-colreorder/js/dataTables.colReorder.min.js"></script>
Name
Age
Address
Action
Christina Bersh 45 4222 River Rd, Columbus
David Harrison 27 2952 S Peoria Ave, Tulsa
Anne Richard 31 255 Dock Ln, New Tazewell
Samia Kartoon 45 4970 Park Ave W, Ohio
David Harrison 27 4222 River Rd, Columbus
Brian Halligan 31 2952 S Peoria Ave, Tulsa
Andy Clerk 45 1818 H St NW, Washington
Bart Simpson 27 3 Grace Dr, New Mexico
Camila Welters 45 4531 W Saile Dr, North Dakota
Oliver Schevich 27 2126 N Eagle, Meridian, Illinois
Inna Ivy 31 3817 Beryl Rd, Nebraska
Jessica Williams 27 4807 3rd Ave, New Hampshire
James Collins 31 Melbourne No. 1 Lake Park
Costa Quinn 27 New York No. 1 Lake Park
Jim Green 27 LA No. 1 Lake Park
Joe Black 31 Sidney No. 1 Lake Park
Isabella Cherry 27 4222 River Rd, Columbus
Alex Tacker 31 2952 S Peoria Ave, Tulsa
Endy Ruiz 45 1818 H St NW, Washington
Jack Li 27 3 Grace Dr, New Mexico
Showing to of users

Export

This example shows how you can add an action such as "Copy", "PDF", etc. to a DataTable.

  1. Install Datatables.net-buttons.

    Install datatables.net-buttons via npm

    npm i datatables.net-buttons jszip pdfmake
  2. Add Datatables.net-buttons to the page.

    Include the JavaScript <script> near the end of your </body> tag:

    <script src="./node_modules/datatables.net-buttons/js/dataTables.buttons.min.js"></script><script src="./node_modules/jszip/dist/jszip.min.js"></script><script src="./node_modules/pdfmake/build/pdfmake.min.js"></script><script src="./node_modules/pdfmake/build/vfs_fonts.js"></script><script src="./node_modules/datatables.net-buttons/js/buttons.html5.min.js"></script><script src="./node_modules/node_modules/datatables.net-buttons/js/buttons.print.min.js"></script>
Name
Age
Address
Action
Christina Bersh 45 4222 River Rd, Columbus
David Harrison 27 2952 S Peoria Ave, Tulsa
Anne Richard 31 255 Dock Ln, New Tazewell
Samia Kartoon 45 4970 Park Ave W, Ohio
David Harrison 27 4222 River Rd, Columbus
Brian Halligan 31 2952 S Peoria Ave, Tulsa
Andy Clerk 45 1818 H St NW, Washington
Bart Simpson 27 3 Grace Dr, New Mexico
Camila Welters 45 4531 W Saile Dr, North Dakota
Oliver Schevich 27 2126 N Eagle, Meridian, Illinois
Inna Ivy 31 3817 Beryl Rd, Nebraska
Jessica Williams 27 4807 3rd Ave, New Hampshire
James Collins 31 Melbourne No. 1 Lake Park
Costa Quinn 27 New York No. 1 Lake Park
Jim Green 27 LA No. 1 Lake Park
Joe Black 31 Sidney No. 1 Lake Park
Isabella Cherry 27 4222 River Rd, Columbus
Alex Tacker 31 2952 S Peoria Ave, Tulsa
Endy Ruiz 45 1818 H St NW, Washington
Jack Li 27 3 Grace Dr, New Mexico

Destroy and Reinitialize New

Provides destroy method that helps to destroy a datatable.

Name
Age
Address
Action
Christina Bersh 45 4222 River Rd, Columbus
David Harrison 27 2952 S Peoria Ave, Tulsa
Anne Richard 31 255 Dock Ln, New Tazewell
Samia Kartoon 45 4970 Park Ave W, Ohio
David Harrison 27 4222 River Rd, Columbus
Brian Halligan 31 2952 S Peoria Ave, Tulsa
Andy Clerk 45 1818 H St NW, Washington
Bart Simpson 27 3 Grace Dr, New Mexico
Camila Welters 45 4531 W Saile Dr, North Dakota
Oliver Schevich 27 2126 N Eagle, Meridian, Illinois
Inna Ivy 31 3817 Beryl Rd, Nebraska
Jessica Williams 27 4807 3rd Ave, New Hampshire
James Collins 31 Melbourne No. 1 Lake Park
Costa Quinn 27 New York No. 1 Lake Park
Jim Green 27 LA No. 1 Lake Park
Joe Black 31 Sidney No. 1 Lake Park
Isabella Cherry 27 4222 River Rd, Columbus
Alex Tacker 31 2952 S Peoria Ave, Tulsa
Endy Ruiz 45 1818 H St NW, Washington
Jack Li 27 3 Grace Dr, New Mexico