- Plugins
- Datatables
Plugins
Tailwind CSS Datatables
Datatables solutions for massive datasets.
Installation
To get started, install Datatables.net plugin via npm with Preline UI's Datatables plugin, you may skip Preline UI's plugin installation step if you are already using Preline UI as a package.
npm i datatables.net-dt @preline/datatable
Example
Here is a basic example of a datatable with advanced features.
|
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 |
CSS
Please add the following CSS to the head. This is necessary because Datatables.net does not allow to add custom markup with options disabled, such as paging: false
or searching: false
.
Methods
The HSDataTable
object is contained within the global window
object
Destroy instance.
const { element } = HSDataTable.getInstance('#datatable', true);
const destroyBtn = document.querySelector('#destroy-btn');
destroyBtn.addEventListener('click', () => {
element.destroy();
});
Events
Datatables.net
Please note that this component requires the use of the Datatables.net plugin. Most events available in the plugin are available in our wrapper.
When datatable redrawn event example.
const { element } = HSDataTable.getInstance('#hs-datatable', true);
const { dataTable } = element;
dataTable.on('draw.dt', () => {
console.log('Table redrawn!');
});
Demo examples
Looking for prebuilt UI components based on the Tailwind CSS? Preline UI packs hundreds of component examples for all your website needs.