search results:

    • Standard
    • React
    License Free hosting Learn Services Community
    • + D
    • Light
    • Dark
    • System
    logo Tailwind Elements
    • Getting started
      • Quick start
      • Tutorials
      • Design system
      • Local installation
      • Optimization
      • Dark mode
      • Theming
      • Changelog
      • Contribute
      • Internationalization guide
    • Integrations
      • Angular
      • Django
      • Express
      • Laravel
      • Next
      • Nuxt
      • React
      • Remix
      • Solid
      • Svelte
      • Vue
    • Content & styles
      • Animations
      • Animations Extended
      • Colors
      • Dividers
      • Figures
      • Headings
      • Hover effects
      • Icons
      • Images
      • Mask
      • Shadows
      • Typography
    • Navigation
      • Breadcrumbs
      • Footer
      • Headers
      • Mega menu
      • Navbar
      • Offcanvas
      • Pagination
      • Pills
      • Scrollspy
      • Sidenav
      • Tabs
    • Components
      • Accordion
      • Alerts
      • Avatar
      • Badges
      • Button group
      • Buttons
      • Cards
      • Carousel
      • Chips
      • Collapse
      • Dropdown
      • Gallery
      • Jumbotron
      • Lightbox
      • Link
      • List group
      • Modal
      • Notifications
      • Paragraphs
      • Placeholders
      • Popconfirm
      • Popover
      • Progress
      • Rating
      • Scroll back to top button
      • Social buttons
      • Spinners
      • Stepper
      • Testimonials
      • Timeline
      • Toast
      • Tooltip
      • Video
      • Video carousel
    • Forms
      • Checkbox
      • Datepicker
      • Datetimepicker
      • File input
      • Form templates
      • Input Group
      • Inputs
      • Login form
      • Radio
      • Range
      • Registration form
      • Search
      • Select
      • Switch
      • Textarea
      • Timepicker
      • Validation
    • Data
      • Charts
      • Charts advanced
      • Datatables
      • Tables
    • Methods
      • Clipboard
      • Infinite scroll
      • Lazy loading
      • Loading management
      • Ripple
      • Scrollbar
      • Smooth scroll
      • Sticky
      • Touch
    • Design Blocks
      • Banners
      • Contact
      • Content
      • CTA
      • FAQ
      • Features
      • Headers
      • Hero / Intro sections
      • Logo clouds
      • Mega menu
      • News
      • Newsletter
      • Pricing
      • Projects
      • Stats
      • Team
      • Testimonials
    • Coming Soon
      • Angular
      • Builder
      • Templates
      • Vue
    • ResourcesNew
      • Playground
      • YouTube Channel
      • Private FB Group
      • Newsletter
      • UI Design course New
      • UI / UX tips
    • Overview
    • API

    Datatables

    Tailwind CSS Datatables

    Use responsive charts component with helper examples for simple chart, line chart, bar chart, radar chart, pie chart, doughnut & more. Open source license.

    Required ES init: Datatable *
    * UMD autoinits are enabled by default. This means that you don't need to initialize the component manually. However if you are using Tailwind Elements ES format then you should pass the required components to the initTE method.

    Basic example - HTML markup

    The Datatable component can render your data in three ways. In the first one, you simply create a HTML markup for your table nested within a div tag with a data-te-datatable-init attribute - you can customize your table later by adding data-te-attributes to the wrapper. Some of the more advanced options for columns, described in the Advanced Data Structure section can be also used by setting data-te-attributes directly to a th tag (f.e. <th data-te-sort="false">).

    Name Position Office Age Start date Salary
    Tiger Nixon System Architect Edinburgh 61 2011/04/25 $320,800
    Garrett Winters Accountant Tokyo 63 2011/07/25 $170,750
    Ashton Cox Junior Technical Author San Francisco 66 2009/01/12 $86,000
    Cedric Kelly Senior Javascript Developer Edinburgh 22 2012/03/29 $433,060
    Airi Satou Accountant Tokyo 33 2008/11/28 $162,700
    Brielle Williamson Integration Specialist New York 61 2012/12/02 $372,000
    Herrod Chandler Sales Assistant San Francisco 59 2012/08/06 $137,500
    Rhona Davidson Integration Specialist Tokyo 55 2010/10/14 $327,900
    Colleen Hurst Javascript Developer San Francisco 39 2009/09/15 $205,500
    Sonya Frost Software Engineer Edinburgh 23 2008/12/13 $103,600
    Jena Gaines Office Manager London 30 2008/12/19 $90,560
    Quinn Flynn Support Lead Edinburgh 22 2013/03/03 $342,000
    Charde Marshall Regional Director San Francisco 36 2008/10/16 $470,600
    Haley Kennedy Senior Marketing Designer London 43 2012/12/18 $313,500
    • HTML
    • javascript
            
                
          <div data-te-datatable-init>
            <table>
              <thead>
                <tr>
                  <th>Name</th>
                  <th>Position</th>
                  <th>Office</th>
                  <th>Age</th>
                  <th>Start date</th>
                  <th>Salary</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>Tiger Nixon</td>
                  <td>System Architect</td>
                  <td>Edinburgh</td>
                  <td>61</td>
                  <td>2011/04/25</td>
                  <td>$320,800</td>
                </tr>
                <tr>
                  <td>Garrett Winters</td>
                  <td>Accountant</td>
                  <td>Tokyo</td>
                  <td>63</td>
                  <td>2011/07/25</td>
                  <td>$170,750</td>
                </tr>
                <tr>
                  <td>Ashton Cox</td>
                  <td>Junior Technical Author</td>
                  <td>San Francisco</td>
                  <td>66</td>
                  <td>2009/01/12</td>
                  <td>$86,000</td>
                </tr>
                <tr>
                  <td>Cedric Kelly</td>
                  <td>Senior Javascript Developer</td>
                  <td>Edinburgh</td>
                  <td>22</td>
                  <td>2012/03/29</td>
                  <td>$433,060</td>
                </tr>
                <tr>
                  <td>Airi Satou</td>
                  <td>Accountant</td>
                  <td>Tokyo</td>
                  <td>33</td>
                  <td>2008/11/28</td>
                  <td>$162,700</td>
                </tr>
                <tr>
                  <td>Brielle Williamson</td>
                  <td>Integration Specialist</td>
                  <td>New York</td>
                  <td>61</td>
                  <td>2012/12/02</td>
                  <td>$372,000</td>
                </tr>
                <tr>
                  <td>Herrod Chandler</td>
                  <td>Sales Assistant</td>
                  <td>San Francisco</td>
                  <td>59</td>
                  <td>2012/08/06</td>
                  <td>$137,500</td>
                </tr>
                <tr>
                  <td>Rhona Davidson</td>
                  <td>Integration Specialist</td>
                  <td>Tokyo</td>
                  <td>55</td>
                  <td>2010/10/14</td>
                  <td>$327,900</td>
                </tr>
                <tr>
                  <td>Colleen Hurst</td>
                  <td>Javascript Developer</td>
                  <td>San Francisco</td>
                  <td>39</td>
                  <td>2009/09/15</td>
                  <td>$205,500</td>
                </tr>
                <tr>
                  <td>Sonya Frost</td>
                  <td>Software Engineer</td>
                  <td>Edinburgh</td>
                  <td>23</td>
                  <td>2008/12/13</td>
                  <td>$103,600</td>
                </tr>
                <tr>
                  <td>Jena Gaines</td>
                  <td>Office Manager</td>
                  <td>London</td>
                  <td>30</td>
                  <td>2008/12/19</td>
                  <td>$90,560</td>
                </tr>
                <tr>
                  <td>Quinn Flynn</td>
                  <td>Support Lead</td>
                  <td>Edinburgh</td>
                  <td>22</td>
                  <td>2013/03/03</td>
                  <td>$342,000</td>
                </tr>
                <tr>
                  <td>Charde Marshall</td>
                  <td>Regional Director</td>
                  <td>San Francisco</td>
                  <td>36</td>
                  <td>2008/10/16</td>
                  <td>$470,600</td>
                </tr>
                <tr>
                  <td>Haley Kennedy</td>
                  <td>Senior Marketing Designer</td>
                  <td>London</td>
                  <td>43</td>
                  <td>2012/12/18</td>
                  <td>$313,500</td>
                </tr>
              </tbody>
            </table>
          </div>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Datatable,
            initTE,
          } from "tw-elements";
    
          initTE({ Datatable });
          
            
        

    Basic data structure

    The second option is a very basic data structure, where columns are represented by an array of strings and so is each row. The table will match each string in a row to a corresponding index in a columns array. This data structure, as it's based on indexes, not key-value pairs, can be easily used for displaying data from the CSV format.

    • HTML
    • javascript
    • umd
            
                
            <div id="datatable"></div>
            
            
        
            
                
            // Initialization for ES Users
            import {
              Datatable,
              initTE,
            } from "tw-elements";
    
            initTE({ Datatable });
    
            const basicData = {
                columns: ['Name', 'Position', 'Office', 'Age', 'Start date', 'Salary'],
                rows: [
                  ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
                  ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
                  ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
                  ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
                  ["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
                  ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
                  ["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
                  ["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
                  ["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
                  ["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
                  ["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
                  ["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
                  ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
                  ["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
                ],
              };
              
            new Datatable(document.getElementById('datatable'), basicData)
            
            
        
            
                
            const basicData = {
              columns: ['Name', 'Position', 'Office', 'Age', 'Start date', 'Salary'],
              rows: [
                ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
                ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
                ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
                ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
                ["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
                ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
                ["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
                ["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
                ["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
                ["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
                ["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
                ["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
                ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
                ["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
              ],
            };
            
            new te.Datatable(document.getElementById('datatable'), basicData)
            
            
        

    Advanced data structure

    The last and most advanced data structure allows customizing each column (sort, width, fixed, field) and matches values from each row to a column in which the `field` equals to a given key value. This data format can be easily used to display JSON data.

    You can also use a mixed version, where columns are an array of object and each row is an array of strings.

    • HTML
    • javascript
    • umd
            
                
              <div id="datatable"></div>
              
            
        
            
                
              // Initialization for ES Users
              import {
                Datatable,
                initTE,
              } from "tw-elements";
    
              initTE({ Datatable });
    
              const advancedData = {
                columns: [
                  { label: 'Name', field: 'name', sort: true },
                  { label: 'Position', field: 'position', sort: false },
                  { label: 'Office', field: 'office', sort: false },
                  { label: 'Age', field: 'age', sort: false },
                  { label: 'Start date', field: 'date', sort: true },
                  { label: 'Salary', field: 'salary', sort: false },
                ],
                rows: [
                  { name: "Tiger Nixon", position: "System Architect", office: "Edinburgh", age: 61, date: "2011/04/25", salary: "$320,800" },
                  { name: "Garrett Winters", position: "Accountant", office: "Tokyo", age: 63, date: "2011/07/25", salary: "$170,750" },
                  { name: "Ashton Cox", position: "Junior Technical Author", office: "San Francisco", age: 66, date: "2009/01/12", salary: "$86,000" },
                  { name: "Cedric Kelly", position: "Senior Javascript Developer", office: "Edinburgh", age: 22, date: "2012/03/29", salary: "$433,060" },
                  { name: "Airi Satou", position: "Accountant", office: "Tokyo", age: 33, date: "2008/11/28", salary: "$162,700" },
                  { name: "Brielle Williamson", position: "Integration Specialist", office: "New York", age: 61, date: "2012/12/02", salary: "$372,000" },
                  { name: "Herrod Chandler", position: "Sales Assistant", office: "San Francisco", age: 59, date: "2012/08/06", salary: "$137,500" },
                  { name: "Rhona Davidson", position: "Integration Specialist", office: "Tokyo", age: 55, date: "2010/10/14", salary: "$327,900" },
                  { name: "Colleen Hurst", position: "Javascript Developer", office: "San Francisco", age: 39, date: "2009/09/15", salary: "$205,500" },
                  { name: "Sonya Frost", position: "Software Engineer", office: "Edinburgh", age: 23, date: "2008/12/13", salary: "$103,600" },
                  { name: "Jena Gaines", position: "Office Manager", office: "London", age: 30, date: "2008/12/19", salary: "$90,560" },
                  { name: "Quinn Flynn", position: "Support Lead", office: "Edinburgh", age: 22, date: "2013/03/03", salary: "$342,000" },
                  { name: "Charde Marshall", position: "Regional Director", office: "San Francisco", age: 36, date: "2008/10/16", salary: "$470,600" },
                  { name: "Haley Kennedy", position: "Senior Marketing Designer", office: "London", age: 43, date: "2012/12/18", salary: "$313,500" }
                ],
              };
              
              new Datatable(document.getElementById('datatable'), advancedData)
              
            
        
            
                
              const advancedData = {
                columns: [
                  { label: 'Name', field: 'name', sort: true },
                  { label: 'Position', field: 'position', sort: false },
                  { label: 'Office', field: 'office', sort: false },
                  { label: 'Age', field: 'age', sort: false },
                  { label: 'Start date', field: 'date', sort: true },
                  { label: 'Salary', field: 'salary', sort: false },
                ],
                rows: [
                  { name: "Tiger Nixon", position: "System Architect", office: "Edinburgh", age: 61, date: "2011/04/25", salary: "$320,800" },
                  { name: "Garrett Winters", position: "Accountant", office: "Tokyo", age: 63, date: "2011/07/25", salary: "$170,750" },
                  { name: "Ashton Cox", position: "Junior Technical Author", office: "San Francisco", age: 66, date: "2009/01/12", salary: "$86,000" },
                  { name: "Cedric Kelly", position: "Senior Javascript Developer", office: "Edinburgh", age: 22, date: "2012/03/29", salary: "$433,060" },
                  { name: "Airi Satou", position: "Accountant", office: "Tokyo", age: 33, date: "2008/11/28", salary: "$162,700" },
                  { name: "Brielle Williamson", position: "Integration Specialist", office: "New York", age: 61, date: "2012/12/02", salary: "$372,000" },
                  { name: "Herrod Chandler", position: "Sales Assistant", office: "San Francisco", age: 59, date: "2012/08/06", salary: "$137,500" },
                  { name: "Rhona Davidson", position: "Integration Specialist", office: "Tokyo", age: 55, date: "2010/10/14", salary: "$327,900" },
                  { name: "Colleen Hurst", position: "Javascript Developer", office: "San Francisco", age: 39, date: "2009/09/15", salary: "$205,500" },
                  { name: "Sonya Frost", position: "Software Engineer", office: "Edinburgh", age: 23, date: "2008/12/13", salary: "$103,600" },
                  { name: "Jena Gaines", position: "Office Manager", office: "London", age: 30, date: "2008/12/19", salary: "$90,560" },
                  { name: "Quinn Flynn", position: "Support Lead", office: "Edinburgh", age: 22, date: "2013/03/03", salary: "$342,000" },
                  { name: "Charde Marshall", position: "Regional Director", office: "San Francisco", age: 36, date: "2008/10/16", salary: "$470,600" },
                  { name: "Haley Kennedy", position: "Senior Marketing Designer", office: "London", age: 43, date: "2012/12/18", salary: "$313,500" }
                ],
              };
              
              new te.Datatable(document.getElementById('datatable'), advancedData)
              
            
        

    Search

    The search field is not a part of the Datatable - place an input field on your page and use .search() method to filter entries.

    • HTML
    • javascript
    • umd
            
                
              <div class="mb-3">
                <div class="relative mb-4 flex w-full flex-wrap items-stretch">
                  <input
                    id="datatable-search-input"
                    type="search"
                    class="relative m-0 -mr-0.5 block w-[1px] min-w-0 flex-auto rounded border border-solid border-neutral-300 bg-transparent bg-clip-padding px-3 py-[0.25rem] text-base font-normal leading-[1.6] text-neutral-700 outline-none transition duration-200 ease-in-out focus:z-[3] focus:border-primary focus:text-neutral-700 focus:shadow-[inset_0_0_0_1px_rgb(59,113,202)] focus:outline-none dark:border-neutral-600 dark:text-neutral-200 dark:placeholder:text-neutral-200 dark:focus:border-primary"
                    placeholder="Search"
                    aria-label="Search"
                    aria-describedby="button-addon1" />
                </div>
              </div>
              <div id="datatable"></div>
              
            
        
            
                
              // Initialization for ES Users
              import {
                Datatable,
                initTE,
              } from "tw-elements";
    
              initTE({ Datatable });
    
              const data = {
                columns: [
                  {
                    label: 'Name',
                    field: 'name'
                  },
                  'Position',
                  'Office',
                  'Age',
                  'Start date',
                  'Salary',
                ],
                rows: [
                  ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
                  ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
                  ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
                  ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
                  ["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
                  ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
                  ["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
                  ["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
                  ["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
                  ["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
                  ["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
                  ["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
                  ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
                  ["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
                ],
              };
              
              const instance = new Datatable(document.getElementById('datatable'), data)
              
              document.getElementById('datatable-search-input').addEventListener('input', (e) => {
                instance.search(e.target.value);
              });
              
            
        
            
                
              const data = {
                columns: [
                  {
                    label: 'Name',
                    field: 'name'
                  },
                  'Position',
                  'Office',
                  'Age',
                  'Start date',
                  'Salary',
                ],
                rows: [
                  ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
                  ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
                  ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
                  ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
                  ["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
                  ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
                  ["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
                  ["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
                  ["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
                  ["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
                  ["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
                  ["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
                  ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
                  ["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
                ],
              };
              
              const instance = new te.Datatable(document.getElementById('datatable'), data)
              
              document.getElementById('datatable-search-input').addEventListener('input', (e) => {
                instance.search(e.target.value);
              });
              
            
        

    Advanced search

    When using the searching method, you can specify which columns it should take under consideration - pass as a second argument a field (or array of fields). By default, searching will apply to all columns.

    • HTML
    • javascript
    • umd
            
                
                <div class="mb-3">
                    <div class="relative mb-4 flex w-full flex-wrap items-stretch">
                    <input
                        id="advanced-search-input"
                        type="search"
                        class="relative m-0 -mr-0.5 block w-[1px] min-w-0 flex-auto rounded-l border border-solid border-neutral-300 bg-transparent bg-clip-padding px-3 py-[0.25rem] text-base font-normal leading-[1.6] text-neutral-700 outline-none transition duration-200 ease-in-out focus:z-[3] focus:border-primary focus:text-neutral-700 focus:shadow-[inset_0_0_0_1px_rgb(59,113,202)] focus:outline-none dark:border-neutral-600 dark:text-neutral-200 dark:placeholder:text-neutral-200 dark:focus:border-primary"
                        placeholder="Search"
                        aria-label="Search"
                        aria-describedby="button-addon1" />
    
                    <!--Search button-->
                    <button
                        class="relative z-[2] flex items-center rounded-r bg-primary px-6 py-2.5 text-xs font-medium uppercase leading-tight text-white shadow-md transition duration-150 ease-in-out hover:bg-primary-700 hover:shadow-lg focus:bg-primary-700 focus:shadow-lg focus:outline-none focus:ring-0 active:bg-primary-800 active:shadow-lg"
                        type="button"
                        id="advanced-search-button"
                        data-te-ripple-init
                        data-te-ripple-color="light">
                        <svg
                        xmlns="http://www.w3.org/2000/svg"
                        viewBox="0 0 20 20"
                        fill="currentColor"
                        class="h-5 w-5">
                        <path
                            fill-rule="evenodd"
                            d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z"
                            clip-rule="evenodd" />
                        </svg>
                    </button>
                    </div>
                </div>
                <div id="datatable"></div>
                
            
        
            
                
                // Initialization for ES Users
                import {
                  Datatable,
                  initTE,
                } from "tw-elements";
    
                initTE({ Datatable });
    
                const data = {
                    columns: [
                      {
                        label: 'Name',
                        field: 'name'
                      },
                      'Position',
                      'Office',
                      'Age',
                      'Start date',
                      'Salary',
                    ],
                    rows: [
                      ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
                      ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
                      ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
                      ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
                      ["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
                      ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
                      ["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
                      ["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
                      ["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
                      ["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
                      ["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
                      ["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
                      ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
                      ["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
                    ],
                  };
    
                  
                const instance = new Datatable(document.getElementById('datatable'), data)
                const advancedSearchInput = document.getElementById('advanced-search-input');
            
                  const search = (value) => {
                    let [phrase, columns] = value.split(" in:").map((str) => str.trim());
            
                    if (columns) {
                      columns = columns.split(",").map((str) => str.toLowerCase().trim());
                    }
            
                    instance.search(phrase, columns);
                  };
            
                  document
                    .getElementById("advanced-search-button")
                    .addEventListener("click", (e) => {
                      search(advancedSearchInput.value);
                    });
            
                  advancedSearchInput.addEventListener("keydown", (e) => {
                    if (e.keyCode === 13) {
                      search(e.target.value);
                    }
                  });
                
            
        
            
                
                const data = {
                  columns: [
                    {
                      label: 'Name',
                      field: 'name'
                    },
                    'Position',
                    'Office',
                    'Age',
                    'Start date',
                    'Salary',
                  ],
                  rows: [
                    ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
                    ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
                    ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
                    ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
                    ["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
                    ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
                    ["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
                    ["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
                    ["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
                    ["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
                    ["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
                    ["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
                    ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
                    ["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
                  ],
                };
    
                
              const instance = new te.Datatable(document.getElementById('datatable'), data)
              const advancedSearchInput = document.getElementById('advanced-search-input');
          
                const search = (value) => {
                  let [phrase, columns] = value.split(" in:").map((str) => str.trim());
          
                  if (columns) {
                    columns = columns.split(",").map((str) => str.toLowerCase().trim());
                  }
          
                  instance.search(phrase, columns);
                };
          
                document
                  .getElementById("advanced-search-button")
                  .addEventListener("click", (e) => {
                    search(advancedSearchInput.value);
                  });
          
                advancedSearchInput.addEventListener("keydown", (e) => {
                  if (e.keyCode === 13) {
                    search(e.target.value);
                  }
                });
                
            
        

    Selectable rows

    When the data-te-selectable option is set to true, user can interact with your table by selecting rows - you can get the selected rows by listening to the selectRows.te.datatable event.

    • HTML
    • javascript
    • umd
            
                
            <div
              id="datatable"
              data-te-selectable="true"
              data-te-multi="true">
            </div>
            
            
        
            
                
            // Initialization for ES Users
            import {
              Datatable,
              initTE,
            } from "tw-elements";
    
            initTE({ Datatable });
    
            const data = {
                columns: [
                  { label: "Name", field: "name" },
                  { label: "Position", field: "position" },
                  { label: "Office", field: "office" },
                  { label: "Age", field: "age" },
                  { label: "Start date", field: "date" },
                  { label: "Salary", field: "salary" },
                ],
                rows: [
                  {
                    name: "Tiger Nixon",
                    position: "System Architect",
                    office: "Edinburgh",
                    age: 61,
                    date: "2011/04/25",
                    salary: "$320,800",
                  },
                  {
                    name: "Garrett Winters",
                    position: "Accountant",
                    office: "Tokyo",
                    age: 63,
                    date: "2011/07/25",
                    salary: "$170,750",
                  },
                  {
                    name: "Ashton Cox",
                    position: "Junior Technical Author",
                    office: "San Francisco",
                    age: 66,
                    date: "2009/01/12",
                    salary: "$86,000",
                  },
                  {
                    name: "Cedric Kelly",
                    position: "Senior Javascript Developer",
                    office: "Edinburgh",
                    age: 22,
                    date: "2012/03/29",
                    salary: "$433,060",
                  },
                  {
                    name: "Airi Satou",
                    position: "Accountant",
                    office: "Tokyo",
                    age: 33,
                    date: "2008/11/28",
                    salary: "$162,700",
                  },
                  {
                    name: "Brielle Williamson",
                    position: "Integration Specialist",
                    office: "New York",
                    age: 61,
                    date: "2012/12/02",
                    salary: "$372,000",
                  },
                  {
                    name: "Herrod Chandler",
                    position: "Sales Assistant",
                    office: "San Francisco",
                    age: 59,
                    date: "2012/08/06",
                    salary: "$137,500",
                  },
                  {
                    name: "Rhona Davidson",
                    position: "Integration Specialist",
                    office: "Tokyo",
                    age: 55,
                    date: "2010/10/14",
                    salary: "$327,900",
                  },
                  {
                    name: "Colleen Hurst",
                    position: "Javascript Developer",
                    office: "San Francisco",
                    age: 39,
                    date: "2009/09/15",
                    salary: "$205,500",
                  },
                  {
                    name: "Sonya Frost",
                    position: "Software Engineer",
                    office: "Edinburgh",
                    age: 23,
                    date: "2008/12/13",
                    salary: "$103,600",
                  },
                  {
                    name: "Jena Gaines",
                    position: "Office Manager",
                    office: "London",
                    age: 30,
                    date: "2008/12/19",
                    salary: "$90,560",
                  },
                  {
                    name: "Quinn Flynn",
                    position: "Support Lead",
                    office: "Edinburgh",
                    age: 22,
                    date: "2013/03/03",
                    salary: "$342,000",
                  },
                  {
                    name: "Charde Marshall",
                    position: "Regional Director",
                    office: "San Francisco",
                    age: 36,
                    date: "2008/10/16",
                    salary: "$470,600",
                  },
                  {
                    name: "Haley Kennedy",
                    position: "Senior Marketing Designer",
                    office: "London",
                    age: 43,
                    date: "2012/12/18",
                    salary: "$313,500",
                  },
                ],
              };
              
            const datatable = document.getElementById('datatable');
              
            new Datatable(datatable, data);
              
            datatable.addEventListener('selectRows.te.datatable', (e) => {
              console.log(e.selectedRows, e.selectedIndexes, e.allSelected);
            })
            
            
        
            
                
            const data = {
              columns: [
                { label: "Name", field: "name" },
                { label: "Position", field: "position" },
                { label: "Office", field: "office" },
                { label: "Age", field: "age" },
                { label: "Start date", field: "date" },
                { label: "Salary", field: "salary" },
              ],
              rows: [
                {
                  name: "Tiger Nixon",
                  position: "System Architect",
                  office: "Edinburgh",
                  age: 61,
                  date: "2011/04/25",
                  salary: "$320,800",
                },
                {
                  name: "Garrett Winters",
                  position: "Accountant",
                  office: "Tokyo",
                  age: 63,
                  date: "2011/07/25",
                  salary: "$170,750",
                },
                {
                  name: "Ashton Cox",
                  position: "Junior Technical Author",
                  office: "San Francisco",
                  age: 66,
                  date: "2009/01/12",
                  salary: "$86,000",
                },
                {
                  name: "Cedric Kelly",
                  position: "Senior Javascript Developer",
                  office: "Edinburgh",
                  age: 22,
                  date: "2012/03/29",
                  salary: "$433,060",
                },
                {
                  name: "Airi Satou",
                  position: "Accountant",
                  office: "Tokyo",
                  age: 33,
                  date: "2008/11/28",
                  salary: "$162,700",
                },
                {
                  name: "Brielle Williamson",
                  position: "Integration Specialist",
                  office: "New York",
                  age: 61,
                  date: "2012/12/02",
                  salary: "$372,000",
                },
                {
                  name: "Herrod Chandler",
                  position: "Sales Assistant",
                  office: "San Francisco",
                  age: 59,
                  date: "2012/08/06",
                  salary: "$137,500",
                },
                {
                  name: "Rhona Davidson",
                  position: "Integration Specialist",
                  office: "Tokyo",
                  age: 55,
                  date: "2010/10/14",
                  salary: "$327,900",
                },
                {
                  name: "Colleen Hurst",
                  position: "Javascript Developer",
                  office: "San Francisco",
                  age: 39,
                  date: "2009/09/15",
                  salary: "$205,500",
                },
                {
                  name: "Sonya Frost",
                  position: "Software Engineer",
                  office: "Edinburgh",
                  age: 23,
                  date: "2008/12/13",
                  salary: "$103,600",
                },
                {
                  name: "Jena Gaines",
                  position: "Office Manager",
                  office: "London",
                  age: 30,
                  date: "2008/12/19",
                  salary: "$90,560",
                },
                {
                  name: "Quinn Flynn",
                  position: "Support Lead",
                  office: "Edinburgh",
                  age: 22,
                  date: "2013/03/03",
                  salary: "$342,000",
                },
                {
                  name: "Charde Marshall",
                  position: "Regional Director",
                  office: "San Francisco",
                  age: 36,
                  date: "2008/10/16",
                  salary: "$470,600",
                },
                {
                  name: "Haley Kennedy",
                  position: "Senior Marketing Designer",
                  office: "London",
                  age: 43,
                  date: "2012/12/18",
                  salary: "$313,500",
                },
              ],
            };
            
            const datatable = document.getElementById('datatable');
            
            new te.Datatable(datatable, data);
            
            datatable.addEventListener('selectRows.te.datatable', (e) => {
              console.log(e.selectedRows, e.selectedIndexes, e.allSelected);
            })
            
            
        

    Scroll

    Setting maximum height/width will enable vertical/horizontal scrolling.

    • HTML
    • javascript
    • umd
            
                
            <div
              id="datatable"
              data-te-max-height="520"
              data-te-max-width="520"></div>
            
            
        
            
                
            // Initialization for ES Users
            import {
              Datatable,
              initTE,
            } from "tw-elements";
    
            initTE({ Datatable });
    
            const basicData = {
                columns: ['Name', 'Position', 'Office', 'Age', 'Start date', 'Salary'],
                rows: [
                  ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
                  ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
                  ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
                  ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
                  ["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
                  ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
                  ["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
                  ["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
                  ["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
                  ["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
                  ["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
                  ["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
                  ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
                  ["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
                ],
              };
              
            const datatable = document.getElementById('datatable');
              
            new Datatable(datatable, basicData);
            
            
        
            
                
            const basicData = {
                columns: ['Name', 'Position', 'Office', 'Age', 'Start date', 'Salary'],
                rows: [
                  ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
                  ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
                  ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
                  ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
                  ["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
                  ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
                  ["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
                  ["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
                  ["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
                  ["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
                  ["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
                  ["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
                  ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
                  ["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
                ],
              };
              
            const datatable = document.getElementById('datatable');
              
            new te.Datatable(datatable, basicData);
            
            
        

    Fixed header

    Use the data-te-fixed-header attribute to ensure that a table's header is always visible while scrolling.

    • HTML
    • javascript
    • umd
            
                
            <div
              id="datatable"
              data-te-max-height="460"
              data-te-fixed-header="true"></div>
            
            
        
            
                
            // Initialization for ES Users
            import {
              Datatable,
              initTE,
            } from "tw-elements";
    
            initTE({ Datatable });
    
            const basicData = {
                columns: ['Name', 'Position', 'Office', 'Age', 'Start date', 'Salary'],
                rows: [
                  ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
                  ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
                  ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
                  ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
                  ["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
                  ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
                  ["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
                  ["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
                  ["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
                  ["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
                  ["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
                  ["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
                  ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
                  ["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
                ],
              };
              
            const datatable = document.getElementById('datatable');
              
            new Datatable(datatable, basicData);
            
            
        
            
                
            const basicData = {
                columns: ['Name', 'Position', 'Office', 'Age', 'Start date', 'Salary'],
                rows: [
                  ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
                  ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
                  ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
                  ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
                  ["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
                  ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
                  ["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
                  ["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
                  ["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
                  ["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
                  ["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
                  ["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
                  ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
                  ["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
                ],
              };
              
            const datatable = document.getElementById('datatable');
              
            new te.Datatable(datatable, basicData);
            
            
        

    Fixed columns

    Making a column sticky requires setting two options - width and fixed. A first option is a number of pixels, while the other one can be either a true ( in which case the column will stick on the left) or a string right.

    Using fixed columns in a vertically scrollable table, requires setting an option fixedHeader to true as well.

    When using a HTML markup instead of a data structure you can still use this feature by setting data-te-width and data-te-fixed attributes on your th tags.

    • HTML
    • javascript
    • umd
            
                
            <div id="datatable"></div>
            
            
        
            
                
            // Initialization for ES Users
            import {
              Datatable,
              initTE,
            } from "tw-elements";
    
            initTE({ Datatable });
    
            const basicData = {
                columns: [
                    { label: 'Name', field: 'name', sort: true, width: 200, fixed: true },
                    { label: 'Position', field: 'position', sort: false, width: 200 },
                    { label: 'Office', field: 'office', sort: false, width: 200, fixed: true },
                    { label: 'Age', field: 'age', sort: false, width: 200 },
                    { label: 'Start date', field: 'date', sort: true, width: 200 },
                    { label: 'Salary', field: 'salary', sort: false, width: 200, fixed: 'right' },
                ],
                rows: [
                    ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
                    ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
                    ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
                    ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
                    ["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
                    ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
                    ["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
                    ["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
                    ["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
                    ["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
                    ["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
                    ["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
                    ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
                    ["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
                ],
            };
              
            const datatable = document.getElementById('datatable');
              
            new Datatable(datatable, basicData);
            
            
        
            
                
            const basicData = {
                columns: [
                    { label: 'Name', field: 'name', sort: true, width: 200, fixed: true },
                    { label: 'Position', field: 'position', sort: false, width: 200 },
                    { label: 'Office', field: 'office', sort: false, width: 200, fixed: true },
                    { label: 'Age', field: 'age', sort: false, width: 200 },
                    { label: 'Start date', field: 'date', sort: true, width: 200 },
                    { label: 'Salary', field: 'salary', sort: false, width: 200, fixed: 'right' },
                ],
                rows: [
                    ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
                    ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
                    ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
                    ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
                    ["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
                    ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
                    ["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
                    ["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
                    ["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
                    ["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
                    ["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
                    ["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
                    ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
                    ["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
                ],
            };
              
            const datatable = document.getElementById('datatable');
              
            new te.Datatable(datatable, basicData);
            
            
        

    Async data

    Loading content asynchronously is an important part of working with data tables - with TE Datatable you can easily display content after fetching it from API by using the update method. Additionally, setting a loading option to true will disable all interactions and display a simple loader while awaiting data.

    The example below demonstrates loading data after the button is pressed.

    • HTML
    • javascript
    • umd
            
                
            <div id="datatable"></div>
            
            
        
            
                
            // Initialization for ES Users
          import {
              Datatable,
              initTE,
            } from "tw-elements";
    
            initTE({ Datatable });
    
            const columns = [
            { label: 'Address', field: 'address' },
            { label: 'Company', field: 'company' },
            { label: 'Email', field: 'email' },
            { label: 'Name', field: 'name' },
            { label: 'Phone', field: 'phone' },
            { label: 'Username', field: 'username' },
            { label: 'Website', field: 'website' },
          ];
          
          const asyncTable = new Datatable(
            document.getElementById('datatable'),
            { columns, },
            { loading: true }
          );
          
          fetch('https://jsonplaceholder.typicode.com/users')
            .then((response) => response.json())
            .then((data) => {
              asyncTable.update(
                {
                  rows: data.map((user) => ({
                    ...user,
                    address: `${user.address.city}, ${user.address.street}`,
                    company: user.company.name,
                  })),
                },
                { loading: false }
              );
            });
            
            
        
            
                
            const columns = [
            { label: 'Address', field: 'address' },
            { label: 'Company', field: 'company' },
            { label: 'Email', field: 'email' },
            { label: 'Name', field: 'name' },
            { label: 'Phone', field: 'phone' },
            { label: 'Username', field: 'username' },
            { label: 'Website', field: 'website' },
          ];
          
          const asyncTable = new te.Datatable(
            document.getElementById('datatable'),
            { columns, },
            { loading: true }
          );
          
          fetch('https://jsonplaceholder.typicode.com/users')
            .then((response) => response.json())
            .then((data) => {
              asyncTable.update(
                {
                  rows: data.map((user) => ({
                    ...user,
                    address: `${user.address.city}, ${user.address.street}`,
                    company: user.company.name,
                  })),
                },
                { loading: false }
              );
            });
            
            
        

    Action buttons

    With the Datatable it's possible to render custom content, such as action buttons and attach listeners to their events. Keep in mind, that the component rerenders content when various actions occur (f.e. sort, search) and event listeners need to be updated. To make it possible, the components emits a custom event render.te.datatable.

    • HTML
    • javascript
    • umd
            
                
              <div id="datatable"></div>
              
            
        
            
                
              // Initialization for ES Users
              import {
                Datatable,
                initTE,
              } from "tw-elements";
    
              initTE({ Datatable });
    
              const customDatatable = document.getElementById("datatable");
    
              const setActions = () => {
                document.querySelectorAll(".call-btn").forEach((btn) => {
                  btn.addEventListener("click", () => {
                    console.log(`call ${btn.attributes["data-te-number"].value}`);
                  });
                });
            
                document.querySelectorAll(".message-btn").forEach((btn) => {
                  btn.addEventListener("click", () => {
                    console.log(
                      `send a message to ${btn.attributes["data-te-email"].value}`
                    );
                  });
                });
              };
            
              customDatatable.addEventListener("render.te.datatable", setActions);
            
              new Datatable(
                customDatatable,
                {
                  columns: [
                    { label: "Name", field: "name" },
                    { label: "Position", field: "position" },
                    { label: "Office", field: "office" },
                    { label: "Contact", field: "contact", sort: false },
                  ],
                  rows: [
                    {
                      name: "Tiger Nixon",
                      position: "System Architect",
                      office: "Edinburgh",
                      phone: "+48000000000",
                      email: "tiger.nixon@gmail.com",
                    },
                    {
                      name: "Sonya Frost",
                      position: "Software Engineer",
                      office: "Edinburgh",
                      phone: "+53456123456",
                      email: "sfrost@gmail.com",
                    },
                    {
                      name: "Tatyana Fitzpatrick",
                      position: "Regional Director",
                      office: "London",
                      phone: "+42123432456",
                      email: "tfitz@gmail.com",
                    },
                  ].map((row) => {
                    return {
                      ...row,
                      contact: `
                          <button
                            type="button"
                            data-te-ripple-init
                            data-te-ripple-color="dark"
                            data-te-number=${row.phone}
                            class="call-btn inline-block rounded-full border border-primary p-1.5 mr-1 uppercase leading-normal shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]">
                            <svg xmlns="http://www.w3.org/2000/svg" fill="#3B71CA" viewBox="0 0 24 24" stroke-width="1.3" stroke="#3B71CA" class="w-4 h-4">
                              <path stroke-linecap="round" stroke-linejoin="round" d="M2.25 6.75c0 8.284 6.716 15 15 15h2.25a2.25 2.25 0 002.25-2.25v-1.372c0-.516-.351-.966-.852-1.091l-4.423-1.106c-.44-.11-.902.055-1.173.417l-.97 1.293c-.282.376-.769.542-1.21.38a12.035 12.035 0 01-7.143-7.143c-.162-.441.004-.928.38-1.21l1.293-.97c.363-.271.527-.734.417-1.173L6.963 3.102a1.125 1.125 0 00-1.091-.852H4.5A2.25 2.25 0 002.25 4.5v2.25z" />
                            </svg>
                          </button>
                          <button
                            type="button"
                            data-te-ripple-init
                            data-te-ripple-color="light"
                            data-te-email=${row.email}
                            class="message-btn inline-block rounded-full border border-primary bg-primary text-white p-1.5 uppercase leading-normal shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]">
                            <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" stroke-width="1.5" stroke="#3B71CA" class="w-4 h-4">
                              <path stroke-linecap="round" stroke-linejoin="round" d="M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75" />
                            </svg>
                          </button>`,
                    };
                  }),
                },
                { hover: true }
              );
              
            
        
            
                
              const customDatatable = document.getElementById("datatable");
    
              const setActions = () => {
                document.querySelectorAll(".call-btn").forEach((btn) => {
                  btn.addEventListener("click", () => {
                    console.log(`call ${btn.attributes["data-te-number"].value}`);
                  });
                });
            
                document.querySelectorAll(".message-btn").forEach((btn) => {
                  btn.addEventListener("click", () => {
                    console.log(
                      `send a message to ${btn.attributes["data-te-email"].value}`
                    );
                  });
                });
              };
            
              customDatatable.addEventListener("render.te.datatable", setActions);
            
              new te.Datatable(
                customDatatable,
                {
                  columns: [
                    { label: "Name", field: "name" },
                    { label: "Position", field: "position" },
                    { label: "Office", field: "office" },
                    { label: "Contact", field: "contact", sort: false },
                  ],
                  rows: [
                    {
                      name: "Tiger Nixon",
                      position: "System Architect",
                      office: "Edinburgh",
                      phone: "+48000000000",
                      email: "tiger.nixon@gmail.com",
                    },
                    {
                      name: "Sonya Frost",
                      position: "Software Engineer",
                      office: "Edinburgh",
                      phone: "+53456123456",
                      email: "sfrost@gmail.com",
                    },
                    {
                      name: "Tatyana Fitzpatrick",
                      position: "Regional Director",
                      office: "London",
                      phone: "+42123432456",
                      email: "tfitz@gmail.com",
                    },
                  ].map((row) => {
                    return {
                      ...row,
                      contact: `
                          <button
                            type="button"
                            data-te-ripple-init
                            data-te-ripple-color="dark"
                            data-te-number=${row.phone}
                            class="call-btn inline-block rounded-full border border-primary p-1.5 mr-1 uppercase leading-normal shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]">
                            <svg xmlns="http://www.w3.org/2000/svg" fill="#3B71CA" viewBox="0 0 24 24" stroke-width="1.3" stroke="#3B71CA" class="w-4 h-4">
                              <path stroke-linecap="round" stroke-linejoin="round" d="M2.25 6.75c0 8.284 6.716 15 15 15h2.25a2.25 2.25 0 002.25-2.25v-1.372c0-.516-.351-.966-.852-1.091l-4.423-1.106c-.44-.11-.902.055-1.173.417l-.97 1.293c-.282.376-.769.542-1.21.38a12.035 12.035 0 01-7.143-7.143c-.162-.441.004-.928.38-1.21l1.293-.97c.363-.271.527-.734.417-1.173L6.963 3.102a1.125 1.125 0 00-1.091-.852H4.5A2.25 2.25 0 002.25 4.5v2.25z" />
                            </svg>
                          </button>
                          <button
                            type="button"
                            data-te-ripple-init
                            data-te-ripple-color="light"
                            data-te-email=${row.email}
                            class="message-btn inline-block rounded-full border border-primary bg-primary text-white p-1.5 uppercase leading-normal shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]">
                            <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" stroke-width="1.5" stroke="#3B71CA" class="w-4 h-4">
                              <path stroke-linecap="round" stroke-linejoin="round" d="M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75" />
                            </svg>
                          </button>`,
                    };
                  }),
                },
                { hover: true }
              );
              
            
        

    Cell formating

    Use cell formatting to color individual cells.

    • HTML
    • javascript
    • umd
            
                
              <div id="datatable" data-te-sort-field="purchases" data-te-sort-order="desc"></div>
              
            
        
            
                
              // Initialization for ES Users
              import {
                Datatable,
                initTE,
              } from "tw-elements";
    
              initTE({ Datatable });
    
              const rows = [
                ["Product 1", 10, 103],
                ["Product 2", 45, 110],
                ["Product 3", 76, 56],
                ["Product 4", 89, 230],
                ["Product 5", 104, 240],
                ["Product 6", 97, 187],
                ["Product 7", 167, 130],
                ["Product 8", 50, 199],
                ["Product 9", 4, 206],
                ["Product 10", 120, 88],
                ["Product 11", 22, 100],
              ];
              const maxValue = Math.max(...rows.map((row) => row[2]));
              const minValue = Math.min(...rows.map((row) => row[2]));
          
              const colors = [
                "bg-[#E3F2FD] dark:bg-[#70a4fa]",
                "bg-[#BBDEFB] dark:bg-[#5e93eb]",
                "bg-[#90CAF9] dark:bg-[#4878c7]",
                "bg-[#64B5F6] dark:bg-[#2463c9]",
                "bg-[#42A5F5] dark:bg-[#124fb3]",
              ];
          
              const step = (maxValue - minValue) / (colors.length - 1);
          
              const formatCell = (cell, value) => {
                const colorIndex = Math.floor((value - minValue) / step);
                const colorClass = colors[colorIndex].split(" ");
          
                colorClass.forEach((className) => {
                  cell.classList.add(className);
                });
              };
          
              const columns = [
                { label: "Product", field: "product" },
                { label: "Quantity", field: "quantity" },
                { label: "Purchases", field: "purchases", format: formatCell },
              ];
          
              new Datatable(document.getElementById("datatable"), {
                columns,
                rows,
              });
              
            
        
            
                
              const rows = [
                ["Product 1", 10, 103],
                ["Product 2", 45, 110],
                ["Product 3", 76, 56],
                ["Product 4", 89, 230],
                ["Product 5", 104, 240],
                ["Product 6", 97, 187],
                ["Product 7", 167, 130],
                ["Product 8", 50, 199],
                ["Product 9", 4, 206],
                ["Product 10", 120, 88],
                ["Product 11", 22, 100],
              ];
              const maxValue = Math.max(...rows.map((row) => row[2]));
              const minValue = Math.min(...rows.map((row) => row[2]));
          
              const colors = [
                "bg-[#E3F2FD] dark:bg-[#70a4fa]",
                "bg-[#BBDEFB] dark:bg-[#5e93eb]",
                "bg-[#90CAF9] dark:bg-[#4878c7]",
                "bg-[#64B5F6] dark:bg-[#2463c9]",
                "bg-[#42A5F5] dark:bg-[#124fb3]",
              ];
          
              const step = (maxValue - minValue) / (colors.length - 1);
          
              const formatCell = (cell, value) => {
                const colorIndex = Math.floor((value - minValue) / step);
                const colorClass = colors[colorIndex].split(" ");
          
                colorClass.forEach((className) => {
                  cell.classList.add(className);
                });
              };
          
              const columns = [
                { label: "Product", field: "product" },
                { label: "Quantity", field: "quantity" },
                { label: "Purchases", field: "purchases", format: formatCell },
              ];
          
              new te.Datatable(document.getElementById("datatable"), {
                columns,
                rows,
              });
              
            
        

    Clickable rows

    Click on the row to preview the message.

    Note: To prevent this action with other clickable elements within the row, call stopPropagation() method.

    Note: This feature cannot be used simultaneously with edit option.

    Modal title
    Modal body text goes here.
    • HTML
    • javascript
    • umd
            
                
                <div
                  id="datatable-clickable-rows"
                  data-te-clickable-rows="true"
                  data-te-selectable="true"
                  data-te-multi="true"></div>
    
                <!-- Modal -->
                <div
                  class="fixed left-0 top-0 z-[1055] hidden h-full w-full overflow-y-auto overflow-x-hidden outline-none"
                  id="modal-clickable-rows"
                  tabindex="-1"
                  aria-labelledby="exampleModalLabel"
                  aria-hidden="true"
                  data-te-modal-init>
                  <div
                    data-te-modal-dialog-ref
                    class="pointer-events-none relative w-auto translate-y-[-50px] opacity-0 transition-all duration-300 ease-in-out min-[576px]:mx-auto min-[576px]:mt-7 min-[576px]:max-w-[500px]">
                    <div
                      class="min-[576px]:shadow-[0_0.5rem_1rem_rgba(#000, 0.15)] pointer-events-auto relative flex w-full flex-col rounded-md border-none bg-white bg-clip-padding text-current shadow-lg outline-none dark:bg-neutral-600">
                        <div
                          id="modal-header-clickable-rows"
                          class="flex flex-shrink-0 items-center justify-between rounded-t-md border-b-2 border-neutral-100 border-opacity-100 p-4 dark:border-opacity-50">
                          <!--Modal title-->
                          <h5
                            class="text-xl font-medium leading-normal text-neutral-800 dark:text-neutral-200"
                            id="exampleModalLabel">
                            Modal title
                          </h5>
                        </div>
    
                          <!--Modal body-->
                        <div
                          id="modal-body-clickable-rows"
                          class="relative flex-auto p-4"
                          data-te-modal-body-ref>
                          Modal body text goes here.
                        </div>
    
                          <!--Modal footer-->
                        <div
                          class="flex flex-shrink-0 flex-wrap items-center justify-end rounded-b-md border-t-2 border-neutral-100 border-opacity-100 p-4 dark:border-opacity-50">
                          <button
                            type="button"
                            class="flex items-center rounded border border-primary px-5 pb-1.5 pt-2 text-xs font-medium uppercase leading-normal text-primary-700 transition duration-150 ease-in-out focus:outline-none focus:ring-0 dark:border-primary-400 dark:text-primary-400"
                            data-te-ripple-init
                            data-te-ripple-color="dark">
                              Reply
                            <svg
                              xmlns="http://www.w3.org/2000/svg"
                              fill="none"
                              viewBox="0 0 24 24"
                              stroke-width="1.5"
                              stroke="currentColor"
                              class="ml-2 h-5 w-5">
                              <path
                                stroke-linecap="round"
                                stroke-linejoin="round"
                                d="M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5" />
                            </svg>
                          </button>
                          <button
                            type="button"
                            class="ml-1 flex items-center rounded border border-primary px-5 pb-1.5 pt-2 text-xs font-medium uppercase leading-normal text-primary-700 transition duration-150 ease-in-out dark:border-primary-400 dark:text-primary-400"
                            data-te-ripple-init
                            data-te-ripple-color="dark">
                            Forward
                            <svg
                             xmlns="http://www.w3.org/2000/svg"
                              fill="none"
                              viewBox="0 0 24 24"
                              stroke-width="1.5"
                              stroke="currentColor"
                              class="ml-2 h-5 w-5">
                              <path
                                stroke-linecap="round"
                                stroke-linejoin="round"
                                d="M13.5 4.5L21 12m0 0l-7.5 7.5M21 12H3" />
                            </svg>
                          </button>
                        </div>
                      </div>
                    </div>
                </div>
                
            
        
            
                
                // Initialization for ES Users
                import {
                  Datatable,
                  Modal,
                  Ripple,
                  initTE,
                } from "tw-elements";
    
                initTE({ Datatable, Modal, Ripple });
    
                const table = document.getElementById("datatable-clickable-rows");
                const modal = document.getElementById("modal-clickable-rows");
                const modalBody = document.getElementById("modal-body-clickable-rows");
                const modalHeader = document.getElementById(
                  "modal-header-clickable-rows"
                );
          
                const modalInstance = new Modal(modal);
          
                const setupButtons = (action) => {
                  document
                    .querySelectorAll(`.${action}-email-button`)
                    .forEach((button) => {
                      button.addEventListener("click", (e) => {
                        e.stopPropagation();
          
                        const index = button.getAttribute("data-te-index");
          
                        console.log(`${action} message: ${index}`, messages[index]);
                      });
                    });
                };
          
                const columnsClickable = [
                  { label: "Actions", field: "actions", sort: false },
                  { label: "From", field: "from" },
                  { label: "Title", field: "title" },
                  { label: "Message", field: "preview", sort: false },
                  { label: "Date", field: "date" },
                ];
          
                const messages = [
                  {
                    from: "admin@mdbootstrap.com",
                    title: "Tailwind Elements spring sale",
                    message:
                      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sed metus ultricies, sollicitudin est nec, blandit turpis. Fusce venenatis nisi volutpat, pharetra elit eu, ullamcorper metus. Vestibulum dapibus laoreet aliquam. Maecenas sed magna ut libero consequat elementum. Maecenas euismod pellentesque pulvinar. Morbi sit amet turpis eget dolor rutrum eleifend. Sed bibendum diam nec diam posuere pulvinar. Cras ac bibendum arcu.",
                    date: "11/12/2019",
                  },
                  {
                    from: "user@mdbootstrap.com",
                    title: "How to use Tailwind Elements?",
                    message:
                      "Quisque tempor ligula eu lobortis scelerisque. Mauris tristique mi a erat egestas, quis dictum nibh iaculis. Sed gravida sodales egestas. In tempus mollis libero sit amet lacinia. Duis non augue sed leo imperdiet efficitur faucibus vitae elit. Mauris eu cursus ligula. Praesent posuere efficitur cursus.",
                    date: "10/12/2019",
                  },
                  {
                    from: "user@mdbootstrap.com",
                    title: "Licence renewal",
                    message:
                      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sed metus ultricies, sollicitudin est nec, blandit turpis. Fusce venenatis nisi volutpat, pharetra elit eu, ullamcorper metus. Vestibulum dapibus laoreet aliquam. Maecenas sed magna ut libero consequat elementum. Maecenas euismod pellentesque pulvinar. Morbi sit amet turpis eget dolor rutrum eleifend. Sed bibendum diam nec diam posuere pulvinar. Cras ac bibendum arcu.",
                    date: "09/12/2019",
                  },
                  {
                    from: "admin@mdbootstrap.com",
                    title: "Black friday offer",
                    message:
                      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sed metus ultricies, sollicitudin est nec, blandit turpis. Fusce venenatis nisi volutpat, pharetra elit eu, ullamcorper metus. Vestibulum dapibus laoreet aliquam. Maecenas sed magna ut libero consequat elementum. Maecenas euismod pellentesque pulvinar. Morbi sit amet turpis eget dolor rutrum eleifend. Sed bibendum diam nec diam posuere pulvinar. Cras ac bibendum arcu.",
                    date: "08/12/2019",
                  },
                ];
          
                const rowsClickable = messages.map((email, i) => {
                  const getPreview = (message, length) => {
                    if (message.length <= length) return message;
          
                    return `${message.slice(0, length)}...`;
                  };
          
                  return {
                    ...email,
                    preview: getPreview(email.message, 20),
                    actions: `
                    <div class="flex">
                      <a role="button" class="star-email-button text-warning" data-te-index="${i}">
                        <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
                          <path stroke-linecap="round" stroke-linejoin="round" d="M11.48 3.499a.562.562 0 011.04 0l2.125 5.111a.563.563 0 00.475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 00-.182.557l1.285 5.385a.562.562 0 01-.84.61l-4.725-2.885a.563.563 0 00-.586 0L6.982 20.54a.562.562 0 01-.84-.61l1.285-5.386a.562.562 0 00-.182-.557l-4.204-3.602a.563.563 0 01.321-.988l5.518-.442a.563.563 0 00.475-.345L11.48 3.5z" />
                        </svg>
                      </a>
                      <a role="button" class="delete-email-button text-neutral-300 ms-2" data-te-index="${i}">
                        <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
                          <path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" />
                        </svg>
                      </a>
                    </div>
                  `,
                  };
                });
          
                table.addEventListener("rowClick.te.datatable", (e) => {
                  const { index } = e;
                  const { message, title, from } = messages[index];
          
                  modalHeader.innerHTML = `
                  <h5 class="text-xl font-medium leading-normal text-neutral-800 dark:text-neutral-200">${title}</h5> 
                  <button
                    id="close-button"
                    type="button"
                    class="box-content rounded-none border-none hover:no-underline hover:opacity-75 focus:opacity-100 focus:shadow-none focus:outline-none"
                    data-te-modal-dismiss
                    aria-label="Close">
                    <svg
                      xmlns="http://www.w3.org/2000/svg"
                      fill="currentColor"
                      viewBox="0 0 24 24"
                      stroke-width="1.5"
                      stroke="currentColor"
                      class="h-6 w-6">
                      <path
                        stroke-linecap="round"
                        stroke-linejoin="round"
                        d="M6 18L18 6M6 6l12 12" />
                    </svg>
                  </button>`;
                  modalBody.innerHTML = `
                  <h6 class="mb-4">From: <strong>${from}</strong></h6>
                  <p>${message}</p>
                `;
          
                  modalInstance.show();
                  document
                    .getElementById("close-button")
                    .addEventListener("click", () => {
                      modalInstance.hide();
                    });
                });
          
                table.addEventListener("render.te.datatable", () => {
                  setupButtons("star");
                  setupButtons("delete");
                });
          
                const datatableInstance = new Datatable(table, {
                  columns: columnsClickable,
                  rows: rowsClickable,
                });
                
            
        
            
                
                const table = document.getElementById("datatable-clickable-rows");
                const modal = document.getElementById("modal-clickable-rows");
                const modalBody = document.getElementById("modal-body-clickable-rows");
                const modalHeader = document.getElementById(
                  "modal-header-clickable-rows"
                );
    
                const modalInstance = new te.Modal(modal);
    
                const setupButtons = (action) => {
                  document
                    .querySelectorAll(`.${action}-email-button`)
                    .forEach((button) => {
                      button.addEventListener("click", (e) => {
                        e.stopPropagation();
    
                        const index = button.getAttribute("data-te-index");
    
                        console.log(`${action} message: ${index}`, messages[index]);
                      });
                    });
                };
    
                const columnsClickable = [
                  { label: "Actions", field: "actions", sort: false },
                  { label: "From", field: "from" },
                  { label: "Title", field: "title" },
                  { label: "Message", field: "preview", sort: false },
                  { label: "Date", field: "date" },
                ];
    
                const messages = [
                  {
                    from: "admin@mdbootstrap.com",
                    title: "Tailwind Elements spring sale",
                    message:
                      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sed metus ultricies, sollicitudin est nec, blandit turpis. Fusce venenatis nisi volutpat, pharetra elit eu, ullamcorper metus. Vestibulum dapibus laoreet aliquam. Maecenas sed magna ut libero consequat elementum. Maecenas euismod pellentesque pulvinar. Morbi sit amet turpis eget dolor rutrum eleifend. Sed bibendum diam nec diam posuere pulvinar. Cras ac bibendum arcu.",
                    date: "11/12/2019",
                  },
                  {
                    from: "user@mdbootstrap.com",
                    title: "How to use Tailwind Elements?",
                    message:
                      "Quisque tempor ligula eu lobortis scelerisque. Mauris tristique mi a erat egestas, quis dictum nibh iaculis. Sed gravida sodales egestas. In tempus mollis libero sit amet lacinia. Duis non augue sed leo imperdiet efficitur faucibus vitae elit. Mauris eu cursus ligula. Praesent posuere efficitur cursus.",
                    date: "10/12/2019",
                  },
                  {
                    from: "user@mdbootstrap.com",
                    title: "Licence renewal",
                    message:
                      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sed metus ultricies, sollicitudin est nec, blandit turpis. Fusce venenatis nisi volutpat, pharetra elit eu, ullamcorper metus. Vestibulum dapibus laoreet aliquam. Maecenas sed magna ut libero consequat elementum. Maecenas euismod pellentesque pulvinar. Morbi sit amet turpis eget dolor rutrum eleifend. Sed bibendum diam nec diam posuere pulvinar. Cras ac bibendum arcu.",
                    date: "09/12/2019",
                  },
                  {
                    from: "admin@mdbootstrap.com",
                    title: "Black friday offer",
                    message:
                      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sed metus ultricies, sollicitudin est nec, blandit turpis. Fusce venenatis nisi volutpat, pharetra elit eu, ullamcorper metus. Vestibulum dapibus laoreet aliquam. Maecenas sed magna ut libero consequat elementum. Maecenas euismod pellentesque pulvinar. Morbi sit amet turpis eget dolor rutrum eleifend. Sed bibendum diam nec diam posuere pulvinar. Cras ac bibendum arcu.",
                    date: "08/12/2019",
                  },
                ];
    
                const rowsClickable = messages.map((email, i) => {
                  const getPreview = (message, length) => {
                    if (message.length <= length) return message;
    
                    return `${message.slice(0, length)}...`;
                  };
    
                  return {
                    ...email,
                    preview: getPreview(email.message, 20),
                    actions: `
                    <div class="flex">
                      <a role="button" class="star-email-button text-warning" data-te-index="${i}">
                        <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
                          <path stroke-linecap="round" stroke-linejoin="round" d="M11.48 3.499a.562.562 0 011.04 0l2.125 5.111a.563.563 0 00.475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 00-.182.557l1.285 5.385a.562.562 0 01-.84.61l-4.725-2.885a.563.563 0 00-.586 0L6.982 20.54a.562.562 0 01-.84-.61l1.285-5.386a.562.562 0 00-.182-.557l-4.204-3.602a.563.563 0 01.321-.988l5.518-.442a.563.563 0 00.475-.345L11.48 3.5z" />
                        </svg>
                      </a>
                      <a role="button" class="delete-email-button text-neutral-300 ms-2" data-te-index="${i}">
                        <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
                          <path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" />
                        </svg>
                      </a>
                    </div>
                  `,
                  };
                });
    
                table.addEventListener("rowClick.te.datatable", (e) => {
                  const { index } = e;
                  const { message, title, from } = messages[index];
    
                  modalHeader.innerHTML = `
                  <h5 class="text-xl font-medium leading-normal text-neutral-800 dark:text-neutral-200">${title}</h5> 
                  <button
                    id="close-button"
                    type="button"
                    class="box-content rounded-none border-none hover:no-underline hover:opacity-75 focus:opacity-100 focus:shadow-none focus:outline-none"
                    data-te-modal-dismiss
                    aria-label="Close">
                    <svg
                      xmlns="http://www.w3.org/2000/svg"
                      fill="currentColor"
                      viewBox="0 0 24 24"
                      stroke-width="1.5"
                      stroke="currentColor"
                      class="h-6 w-6">
                      <path
                        stroke-linecap="round"
                        stroke-linejoin="round"
                        d="M6 18L18 6M6 6l12 12" />
                    </svg>
                  </button>`;
                  modalBody.innerHTML = `
                  <h6 class="mb-4">From: <strong>${from}</strong></h6>
                  <p>${message}</p>
                `;
    
                  modalInstance.show();
                  document
                    .getElementById("close-button")
                    .addEventListener("click", () => {
                      modalInstance.hide();
                    });
                });
    
                table.addEventListener("render.te.datatable", () => {
                  setupButtons("star");
                  setupButtons("delete");
                });
    
                const datatableInstance = new te.Datatable(table, {
                  columns: columnsClickable,
                  rows: rowsClickable,
                });
                
            
        

    Related resources

    Tables

    If you are looking for more advanced options, try Bootstrap Datatables from MDBootstrap.

    • Basic example
    • Basic data structure
    • Advanced data structure
    • Search
    • Advanced search
    • Selectable
    • Scroll
    • Fixed header
    • Fixed columns
    • Async data
    • Action buttons
    • Custom cell formating
    • Clickable rows
    • Related resources

    Datatables - API


    Import

    Importing components depends on how your application works. If you intend to use the Tailwind Elements ES format, you must first import the component and then initialize it with the initTE method. If you are going to use the UMD format, just import the tw-elements package.

    • javascript
    • umd
            
                
            import { Datatable, initTE } from "tw-elements";
            initTE({ Datatable });
            
            
        
            
                
            import "tw-elements";
            
            
        

    Usage

    Via data attributes

    Using the Datatable component doesn't require any additional JavaScript code - simply add a div wrapper with a data-te-datatable-init attribute to your table and use other data attributes to set all options. For ES format, you must first import and call the initTE method.

    • HTML
            
                
            <div data-te-datatable-init></div>
            
            
        

    Via JavaScript

    • javascript
    • umd
            
                
            const myDatatable = new Datatable(document.getElementById('datatable'), data, options, classes);
            
            
        
            
                
            const myDatatable = new te.Datatable(document.getElementById('datatable'), data, options, classes);
            
            
        

    Options

    Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-te-, as in data-te-all-text="".

    Name Type Default Description
    allText String "All" Changes text for All in the pagination select
    bordered Boolean false Adds borders to a datatable.
    borderless Boolean false Removes all borders from a datatable.
    clickableRows Boolean false Makes rows clickable.
    defaultValue String - This string will be used as a placeholder if a row doesn't have a defined value for a column.
    edit Boolean false Enables edit mode.
    entries Number 10 Number of visible entries (pagination).
    entriesOptions Array [10, 25, 50, 200] Options available to choose from in a pagination select (rows per page). Array with the available options may contain numbers and 'All' to display all entries on single page.
    fixedHeader Boolean false When it's set to true, the table's header will remain visible while scrolling.
    forceSort Boolean false When it's set to true, the table's sort will toggle between two options: ascending and descending. The initial state will not be one of the options.
    fullPagination Boolean false Displays additional buttons for the first and last pages.
    hover Boolean false Changes the background color of a hovered row.
    loading Boolean false Sets the loading mode - disables interactions and displays a loader.
    loadingMessage String "Loading results..." A message displayed while loading data.
    maxHeight Number|String - Sets a maximum height of a datatable - can be either a string ('10%') or a number of pixels.
    maxWidth Number|String - Sets a maximum width of a datatable - can be either a string ('10%') or a number of pixels.
    multi Boolean false Allows selecting multiple rows (selectable mode).
    noFoundMessage String "No matching results found" A message displayed when a table is empty.
    ofText String "of" A message displayed as pagination description.
    pagination Boolean true Shows/hides the pagination panel.
    paginationEndIconTemplate String <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4"> <path stroke-linecap="round" stroke-linejoin="round" d="M11.25 4.5l7.5 7.5-7.5 7.5m-6-15l7.5 7.5-7.5 7.5"/></svg> Changes pagination end button template.
    paginationLeftIconTemplate String <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4"> <path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5L8.25 12l7.5-7.5" /></svg> Changes pagination left button template.
    paginationRightIconTemplate String <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4"> <path stroke-linecap="round" stroke-linejoin="round" d="M8.25 4.5l7.5 7.5-7.5 7.5" /></svg> Changes pagination right button template.
    paginationStartIconTemplate String <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4"> <path stroke-linecap="round" stroke-linejoin="round" d="M18.75 19.5l-7.5-7.5 7.5-7.5m-6 15L5.25 12l7.5-7.5" /></svg> Changes pagination start button template.
    rowsText String "Rows per page:" A text indicating a number of rows per page.
    selectable Boolean false Enables selecting rows with checkboxes.
    sortIconTemplate String <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" stroke-width="3" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 10.5L12 3m0 0l7.5 7.5M12 3v18" /> </svg> Changes sort icon template.
    sm Boolean false Decreases a row's paddings.
    sortField String|Null null Sorts given field on init. To use it via data attributes additionally data-te-field attribute needs to be added to column th element. e.g. <th data-te-field="age">Age</th>
    sortOrder String "asc" Defines an order in which initial sorting will sort. Use 'asc' for ascending order, and 'desc' for descending order (works only when data is injected with JS)
    striped Boolean false Slightly changes the background's color in every other row.

    Options (column)

    Name Type Default Description
    field String - A field's name - will be used as a key for values in rows.
    fixed Boolean|String false When set to true, makes a column stick on the left while scrolling. Changing its value to right will do the same on the other side. For this option to work, you need to define width as well.
    format(cell, value) Function - Function runs for each cell, taking the DOM node & cell's value as its parameters.
    label String - A displayed header of a column.
    sort Boolean true Enables/disables sorting for this column.
    width Number - A column's width in pixels.

    Classes

    Custom classes can be passed via data attributes or JavaScript. For data attributes, append the class name to data-te-class, as in data-te-class-border-color="".

    Name Default Description
    borderColor border-neutral-200 dark:border-neutral-500 Sets border color of datatable.
    borderless border-none Sets border styles when data-te-borderless="true".
    checkboxHeader relative float-left -ml-[1.5rem] mr-[6px] mt-[0.15rem] h-[1.125rem] w-[1.125rem] appearance-none rounded-[0.25rem] border-[0.125rem] border-solid border-neutral-300 outline-none before:pointer-events-none before:absolute before:h-[0.875rem] before:w-[0.875rem] before:scale-0 before:rounded-full before:bg-transparent before:opacity-0 before:shadow-[0px_0px_0px_13px_transparent] before:content-[''] checked:border-primary checked:bg-primary checked:before:opacity-[0.16] checked:after:absolute checked:after:-mt-px checked:after:ml-[0.25rem] checked:after:block checked:after:h-[0.8125rem] checked:after:w-[0.375rem] checked:after:rotate-45 checked:after:border-[0.125rem] checked:after:border-l-0 checked:after:border-t-0 checked:after:border-solid checked:after:border-white checked:after:bg-transparent checked:after:content-[''] hover:cursor-pointer hover:before:opacity-[0.04] hover:before:shadow-[0px_0px_0px_13px_rgba(0,0,0,0.6)] focus:shadow-none focus:transition-[border-color_0.2s] focus:before:scale-100 focus:before:opacity-[0.12] focus:before:shadow-[0px_0px_0px_13px_rgba(0,0,0,0.6)] focus:before:transition-[box-shadow_0.2s,transform_0.2s] focus:after:absolute focus:after:z-[1] focus:after:block focus:after:h-[0.875rem] focus:after:w-[0.875rem] focus:after:rounded-[0.125rem] focus:after:content-[''] checked:focus:before:scale-100 checked:focus:before:shadow-[0px_0px_0px_13px_#3b71ca] checked:focus:before:transition-[box-shadow_0.2s,transform_0.2s] checked:focus:after:-mt-px checked:focus:after:ml-[0.25rem] checked:focus:after:h-[0.8125rem] checked:focus:after:w-[0.375rem] checked:focus:after:rotate-45 checked:focus:after:rounded-none checked:focus:after:border-[0.125rem] checked:focus:after:border-l-0 checked:focus:after:border-t-0 checked:focus:after:border-solid checked:focus:after:border-white checked:focus:after:bg-transparent dark:border-neutral-600 dark:checked:border-primary dark:checked:bg-primary dark:focus:before:shadow-[0px_0px_0px_13px_rgba(255,255,255,0.4)] dark:checked:focus:before:shadow-[0px_0px_0px_13px_#3b71ca] dark:border-neutral-400 Sets checkbox header styles.
    checkboxHeaderWrapper mb-[0.125rem] min-h-[1.5rem] pl-[1.5rem] ml-3 flex items-center Sets checkbox header wrapper styles.
    checkboxRow relative float-left -ml-[1.5rem] mr-[6px] mt-[0.15rem] h-[1.125rem] w-[1.125rem] appearance-none rounded-[0.25rem] border-[0.125rem] border-solid border-neutral-300 outline-none before:pointer-events-none before:absolute before:h-[0.875rem] before:w-[0.875rem] before:scale-0 before:rounded-full before:bg-transparent before:opacity-0 before:shadow-[0px_0px_0px_13px_transparent] before:content-[''] checked:border-primary checked:bg-primary checked:before:opacity-[0.16] checked:after:absolute checked:after:-mt-px checked:after:ml-[0.25rem] checked:after:block checked:after:h-[0.8125rem] checked:after:w-[0.375rem] checked:after:rotate-45 checked:after:border-[0.125rem] checked:after:border-l-0 checked:after:border-t-0 checked:after:border-solid checked:after:border-white checked:after:bg-transparent checked:after:content-[''] hover:cursor-pointer hover:before:opacity-[0.04] hover:before:shadow-[0px_0px_0px_13px_rgba(0,0,0,0.6)] focus:shadow-none focus:transition-[border-color_0.2s] focus:before:scale-100 focus:before:opacity-[0.12] focus:before:shadow-[0px_0px_0px_13px_rgba(0,0,0,0.6)] focus:before:transition-[box-shadow_0.2s,transform_0.2s] focus:after:absolute focus:after:z-[1] focus:after:block focus:after:h-[0.875rem] focus:after:w-[0.875rem] focus:after:rounded-[0.125rem] focus:after:content-[''] checked:focus:before:scale-100 checked:focus:before:shadow-[0px_0px_0px_13px_#3b71ca] checked:focus:before:transition-[box-shadow_0.2s,transform_0.2s] checked:focus:after:-mt-px checked:focus:after:ml-[0.25rem] checked:focus:after:h-[0.8125rem] checked:focus:after:w-[0.375rem] checked:focus:after:rotate-45 checked:focus:after:rounded-none checked:focus:after:border-[0.125rem] checked:focus:after:border-l-0 checked:focus:after:border-t-0 checked:focus:after:border-solid checked:focus:after:border-white checked:focus:after:bg-transparent dark:border-neutral-600 dark:checked:border-primary dark:checked:bg-primary dark:focus:before:shadow-[0px_0px_0px_13px_rgba(255,255,255,0.4)] dark:checked:focus:before:shadow-[0px_0px_0px_13px_#3b71ca] dark:border-neutral-400 Sets checkbox row styles.
    checkboxRowWrapper mb-[0.125rem] min-h-[1.5rem] pl-[1.5rem] ml-3 flex items-center Sets checkbox row wrapper styles.
    color bg-white dark:bg-neutral-800 Sets background styles of datatable.
    column py-4 pl-1 text-clip overflow-hidden text-[#212529] dark:text-white Sets table columns styles.
    edit focus:outline-none Sets row items styles when data-te-edit="true".
    fixedHeader sticky top-0 z-30 Sets table header styles when data-te-fixed-header="true.
    fixedHeaderBody sticky z-10 bg-inherit Sets table body styles when data-te-fixed-header="true.
    hoverRow hover:bg-neutral-100 dark:hover:bg-neutral-700 Sets row hover styles when data-te-hover="true.
    loadingColumn pointer-events-none cursor-none text-neutral-400 dark:text-neutral-300 Sets column styles when data-te-loading="true".
    loadingItemsWrapper h-[2px] relative w-full overflow-hidden Sets loading items wrapper styles.
    loadingMessage text-center text-neutral-500 font-ligh text-sm my-4 dark:text-neutral-400 Sets loading message styles.
    loadingPaginationNav text-neutral-500 dark:text-neutral-300 Sets loading pagination nav styles when data-te-loading="true".
    loadingPaginationRowsText text-neutral-500 dark:text-neutral-300 Sets loading pagination rows text styles when data-te-loading="true".
    loadingPaginationSelectWrapper pointer-events-none cursor-none Sets loading pagination select wrapper styles when data-te-loading="true".
    loadingProgressBar h-full w-[45%] bg-primary-400 dark:bg-primary-600 Sets loading progress bar styles.
    loadingProgressBarWrapper h-full animate-[progress_3s_ease-in-out_infinite] Sets loading progress bar wrapper styles.
    noFoundMessage pl-2 py-3 font-light text-sm dark:text-neutral-300 Sets no found message styles.
    noFoundMessageWrapper border-b Sets no found message wrapper styles.
    pagination flex md:flex-row justify-end items-center py-2 space-x-4 text-sm flex-col leading-[1.6] Sets datatable pagination styles.
    paginationBordered border border-t-0 Sets pagination border styles when data-te-bordered="true".
    paginationButtonsWrapper order-1 my-3 md:order-none md:my-0 md:pr-1 Sets pagination buttons wrapper styles.
    paginationEndButton inline-block rounded p-2.5 text-xs font-medium uppercase leading-normal transition duration-150 ease-in-out hover:bg-neutral-100 hover:text-primary-600 focus:text-primary-600 focus:outline-none focus:ring-0 active:text-primary-700 disabled:text-slate-300 disabled:hover:bg-transparent dark:hover:bg-neutral-500 dark:disabled:hover:bg-transparent dark:disabled:text-neutral-600 Sets pagination end button styles.
    paginationLeftButton inline-block rounded p-2.5 font-medium uppercase leading-normal transition duration-150 ease-in-out hover:bg-neutral-100 hover:text-primary-600 focus:text-primary-600 focus:outline-none focus:ring-0 active:text-primary-700 disabled:text-slate-300 disabled:hover:bg-transparent dark:hover:bg-neutral-500 dark:disabled:hover:bg-transparent dark:disabled:text-neutral-600 Sets pagination left button styles.
    paginationNav font-normal order-2 mb-3 md:order-none md:mb-0 Sets pagination nav styles.
    paginationRightButton inline-block rounded p-2.5 font-medium uppercase leading-normal transition duration-150 ease-in-out hover:bg-neutral-100 hover:text-primary-600 focus:text-primary-600 focus:outline-none focus:ring-0 active:text-primary-700 disabled:text-slate-300 disabled:hover:bg-transparent dark:hover:bg-neutral-500 dark:disabled:hover:bg-transparent dark:disabled:text-neutral-600 Sets pagination right button styles.
    paginationRowsText font-light Sets pagination rows text styles.
    paginationStartButton inline-block rounded p-2.5 font-medium uppercase leading-normal transition duration-150 ease-in-out hover:bg-neutral-100 hover:text-primary-600 focus:text-primary-600 focus:outline-none focus:ring-0 active:text-primary-700 disabled:text-slate-300 disabled:hover:bg-transparent dark:hover:bg-neutral-500 dark:disabled:hover:bg-transparent dark:disabled:text-neutral-600 Sets pagination start button styles.
    row border-b Sets row styles.
    rowAnimation transition ease-in-out duration-300 motion-reduce:transition-none Sets row animation styles.
    rowItem whitespace-nowrap text-clip overflow-hidden px-[1.4rem] py-4 Sets row item styles.
    scroll relative Sets scroll position styles.
    selectableRow !bg-neutral-100 dark:!bg-neutral-600 Sets row background styles when it is selected.
    selectItemsWrapper flex items-center space-x-4 order-3 md:order-none Sets select items wrapper styles.
    selectWrapper w-[70px] Sets select wrapper styles.
    sm !py-2 Sets rows padding styles when data-te-sm="true".
    sortIcon w-[15px] h-[10px] origin-bottom font-black mr-1 opacity-0 text-neutral-500 group-hover:opacity-100 transition hover:ease-in-out transform ease-linear duration-300 motion-reduce:transition-none dark:text-neutral-400 Sets sort icon styles.
    sortIconWrapper flex flex-row group Sets sort icon wrapper styles.
    striped [&:nth-child(odd)]:bg-neutral-50 [&:nth-child(odd)]:dark:bg-neutral-700 Sets rows border styles when data-te-striped="true".
    tableBordered border Sets table border styles when data-te-bordered="true".
    tableHeader border-b font-normal px-[1.4rem] Sets table header styles.
    table text-left text-sm font-light w-full leading-[1.6] Sets table styles.

    Methods

    Method Description Example
    dispose Removes the component's instance. myDatatable.dispose()
    getOrCreateInstance Static method which returns the datatable instance associated to a DOM element or create a new one in case it wasn't initialized. myDatatable.getOrCreateInstance()
    getInstance Static method which allows you to get the datatable instance associated to a DOM element. myDatatable.getInstance()
    search Filters rows so there are only those containing the searched phrase. myDatatable.search(phrase: String, column: String|Array (optional))
    setActivePage Sets a specific page of entries. Page count starts from 0. myDatatable.setActivePage(index)
    update Updates and rerenders datatable. myDatatable.update(data: Object, options: Object)
    • javascript
    • umd
            
                
            const myDatatableEl = document.getElementById('myDatatable');
            const myDatatable = new Datatable(myDatatableEl);
            myDatatable.update({ rows: [...], columns: [...]}, { bordered: true, loading: false });
            
            
        
            
                
            const myDatatableEl = document.getElementById('myDatatable');
            const myDatatable = new te.Datatable(myDatatableEl);
            myDatatable.update({ rows: [...], columns: [...]}, { bordered: true, loading: false })
            
            
        

    Events

    Event type Description
    render.te.datatable Event emitted after the component renders/updates rows.
    rowClick.te.datatable Event emitted after clicking on a row.
    selectRows.te.datatable This event fires when a user select rows with checkboxes. You can acquire more information about selected rows with the following properties of an emitted event: selectedRows: Array, selectedIndexes: Array, allSelected: Boolean.
    update.te.datatable This event fires in an editable mode when a user updates values. You can access the updated data inside a listener's handler with event.rows and event.columns fields.
    • JavaScript
            
                
            const myDatatable= document.getElementById('myDatatable');
            myDatatable.addEventListener('render.te.datatable', (e) => {
              // do something...
            });
            
            
        
    • Import
    • Usage
    • Options
    • Options (column)
    • Classes
    • Methods
    • Events
    Get useful tips & free resources directly to your inbox along with exclusive subscriber-only content.
    Join our mailing list now
    © 2023 Copyright: MDBootstrap.com