Home » Web Tutorials » Weebly » How to Add an Advanced Data Table in Weebly?

How to Add an Advanced Data Table in Weebly?

Weebly offers an official Simple Table app, and there are several other ways to insert tables into your site. However, unlike WordPress, which offers dedicated plugins for creating advanced tables, Weebly does not have a built-in option for adding feature-rich data tables with sorting, searching, filtering, and pagination. In our earlier article, we explained how to create advanced data tables using the Bootstrap framework. Unfortunately, Bootstrap may conflict with many Weebly themes and break the existing layout or styling. Although Weebly makes it easy to insert custom CSS, JavaScript, and HTML code, the safer approach is to create a data table without Bootstrap so that it blends naturally with your site’s theme.

In this article, we will explain how to create an advanced data table in Weebly using the DataTables JavaScript library without Bootstrap.

What is a Data Table?

A basic table can quickly become difficult to navigate when displaying large datasets. Data tables solve this problem by improving usability and helping visitors quickly find the information they need. An advanced data table allows you to display large amounts of content in an organized table format with interactive features such as sorting, filtering, searching, and pagination. The plain table will look like below:

Weebly Data Table Widget

You can use a data table on your Weebly site to display content such as product lists, employee directories, pricing information, schedules, statistics, or comparison charts. The widget includes the following features:

  • Fully responsive design created using HTML table tags, CSS, and JavaScript.
  • Built-in search box for dynamically filtering content.
  • Sorting functionality for arranging data by columns.
  • Pagination controls for navigating between pages.
  • Configurable row display options such as 10, 25, 50, or 100 records per page.
  • Entry counter showing the number of displayed records and the total number of entries.

Adding a Data Table in Weebly

The official DataTables website offers many customization options, which may feel overwhelming for beginners. To keep things simple, we will focus on four basic table styles that work well in Weebly. You can also check the live demos to preview how each style looks before adding it to your website:

  • Plain striped data table > View demo.
  • Striped table with hover highlight > View demo.
  • Table with row and cell borders > View demo.
  • Search box only table (without filtering, sorting, or pagination) > View demo.

Note: This is not a Weebly app. You must prepare the table data offline using standard HTML <table> tags and then insert the code using the Embed Code element in the Weebly editor. Although DataTables technically supports unlimited rows, Weebly may struggle with extremely large tables. If performance becomes an issue, split the content into multiple smaller tables. Also note that the font style, size, spacing, and colors may vary depending on your Weebly theme.

Inserting CSS and Scripts in Weebly

If you are creating only one table, the easiest method is to insert the entire code (including CSS and JavaScript) using a single Embed Code element.

Adding Custom HTML with Embed Code Element in Weebly

Alternatively, go to “Pages > Select Your Page > SEO Settings” and paste the CSS CDN link inside the Header Code section and the JavaScript files inside the Footer Code section.

Add Page Level CSS and JS in Weebly

If you plan to use multiple tables across different pages, it is better to add the CSS and JavaScript globally by navigating to “Settings > SEO” and paste the CSS link in the Header Code box and the JavaScript files in the Footer Code box. This avoids repeating the same code on every page.

Add Site Level CSS and JS in Weebly

Code Required for the Data Table

The implementation consists of three parts:

  1. CSS stylesheet
  2. JavaScript files
  3. HTML table structure

Step 1: Add the CSS File

Use the following CDN stylesheet for DataTables:

<link rel="stylesheet" href="https://cdn.datatables.net/2.3.6/css/dataTables.dataTables.css">

Step 2: Add JavaScript Files

Insert the following jQuery and DataTables script files:

<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://cdn.datatables.net/2.3.6/js/dataTables.js"></script>

You must initialize the table using JavaScript. The table ID used in the initialization script should match the ID in your HTML table. For example, #mytable1 is the ID used in the below initialization script:

<script>
new DataTable('#mytable1', {
lengthMenu: [25, 50, -1]
});
</script>

Step 3: Complete HTML Example

Below is a sample employee data table with five rows. You can add as many rows as needed. The CSS class="display" determines the table style.

<link rel="stylesheet" href="https://cdn.datatables.net/2.3.6/css/dataTables.dataTables.css">
<table id="mytable1" class="display">
    <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>Adam Pierce</td>
            <td>Software Engineer</td>
            <td>New York</td>
            <td>29</td>
            <td>2016-03-14</td>
            <td>$125,000</td>
        </tr>
        <tr>
            <td>Linda Howard</td>
            <td>Project Manager</td>
            <td>London</td>
            <td>41</td>
            <td>2014-09-22</td>
            <td>$185,400</td>
        </tr>
        <tr>
            <td>Kevin Morales</td>
            <td>Data Analyst</td>
            <td>San Francisco</td>
            <td>34</td>
            <td>2018-01-08</td>
            <td>$142,750</td>
        </tr>
        <tr>
            <td>Sophia Turner</td>
            <td>UX Designer</td>
            <td>Berlin</td>
            <td>27</td>
            <td>2019-06-17</td>
            <td>$98,500</td>
        </tr>
        <tr>
            <td>Daniel Brooks</td>
            <td>DevOps Engineer</td>
            <td>Seattle</td>
            <td>38</td>
            <td>2015-11-02</td>
            <td>$176,300</td>
        </tr>
    </tbody>
</table>
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://cdn.datatables.net/2.3.6/js/dataTables.js"></script>
<script>
new DataTable('#mytable1', {
    lengthMenu: [10, 25, 50, 100]
});
</script>

Customizing the Data Table

You can easily change the appearance of your table by modifying the CSS class used in the HTML <table> tag.

  • Plain Table: This provides the standard DataTables appearance with a fixed striped display using class="stripe".
  • Striped Table: This style highlights the alternative rows on mouse hover using class="display".
  • Bordered Table: This is a plain table with borders around rows and cells using class="row-border" and class="cell-border".
  • Search-Only Table: If you only want the search box and want to remove pagination, sorting, and entry information, use the following initialization script. This can be used with any of the above styles.
<script>
new DataTable('#mytable1', {
    info: false,
    ordering: false,
    paging: false
});
</script>

Leave a Comment

Your email address will not be published. Required fields are marked *