DEV Community

Cover image for Simplifying Data Table Management with EzyTables
Carlos Nah
Carlos Nah

Posted on

Simplifying Data Table Management with EzyTables

Data tables are a fundamental component of many web applications. They help organize, display, and manage tabular data efficiently. Regardless of the framework or library you're using, managing data tables can sometimes be a challenging task. To address these challenges and simplify data table management, we introduce EzyTables, a minimalist JavaScript library.

In this blog post, we'll explore the benefits of using EzyTables and demonstrate how it can enhance data table handling in a framework-agnostic context.

The Challenges of Data Table Management

Managing data tables in web applications comes with a set of common challenges:

  1. Reactivity: Ensuring that your data table updates and reflects changes promptly, such as sorting, filtering, or searching.

  2. Complexity: Writing and maintaining custom code for data table functionality can quickly become complex and hard to manage.

  3. Performance: As your dataset grows, handling rendering, sorting, and filtering efficiently can be a performance bottleneck.

  4. Data Fetching: When working with remote data sources, fetching data from a server and integrating it into your data table can be a significant challenge.

Meet EzyTables

EzyTables is a lightweight, framework-agnostic JavaScript library that simplifies data table management. It offers several key features:

  1. Reactivity: EzyTables leverages the reactivity system to ensure that your data table automatically updates when data changes. Whether it's sorting, searching, or filtering, your table stays up-to-date.

  2. Simplicity: Creating and managing data tables becomes effortless with EzyTables. It eliminates the need for intricate custom code, allowing you to set up a data table with minimal effort.

  3. Customization: While EzyTables provides essential data table functionality, it also allows for customization. You can define your rendering logic, ensuring that your data table looks and behaves exactly as you want.

  4. Pagination: EzyTables includes built-in support for pagination. This makes it easy to handle large datasets while maintaining optimal performance.

  5. Server-Side Data Fetching: If your application requires data from a server, EzyTables can handle server-side data fetching efficiently, while still providing a smooth user experience.

Using EzyTables in a Framework-Agnostic Context

EzyTables is designed to be framework-agnostic, which means you can use it with any web framework or even without one. Let's take a look at a simple example of using EzyTables in a framework-agnostic context:

<!DOCTYPE html>
<html>
  <head>
    <title>EzyTables Example</title>
  </head>
  <body>
    <div class="table-controls">
      <label for="limitSelect">Show</label>
      <select id="limitSelect">
        <option value="10">10</option>
        <option value="20">20</option>
        <option value="50">50</option>
      </select>
      <label for="searchInput">Search</label>
      <input id="searchInput" placeholder="Search..." />
    </div>
    <table id="myTable">
      <thead>
        <tr>
          <th>Name</th>
          <th>Description</th>
          <th>Status</th>
          <th>Date</th>
        </tr>
      </thead>
      <tbody></tbody>
    </table>
    <div class="pagination">
      <button id="prevButton">Prev</button>
      <button id="nextButton">Next</button>
    </div>
    <p id="paginationInfo"></p>

    <script type="module">
       import { EzyTables } from 'https://esm.run/ezytables';
    </script>
    <script>
      const data = [
        {
          name: "John Brown",
          description:
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor, nisl eget ultricies aliquam, nunc nisl aliquet nunc, vitae aliquam nisl nunc eu nisi. Sed vitae nisl eget nisl aliquam aliquet. Sed vitae nisl eget nisl aliquam aliquet.",
          status: "Active",
          date: "2020-01-01",
        },
        {
          name: "Jane Abram",
          description:
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor, nisl eget ultricies aliquam, nunc nisl aliquet nunc, vitae aliquam nisl nunc eu nisi. Sed vitae nisl eget nisl aliquam aliquet. Sed vitae nisl eget nisl aliquam aliquet.",
          status: "Active",
          date: "2020-01-01",
        },
        {
          name: "Sam Smith",
          description:
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor, nisl eget ultricies aliquam, nunc nisl aliquet nunc, vitae aliquam nisl nunc eu nisi. Sed vitae nisl eget nisl aliquam aliquet. Sed vitae nisl eget nisl aliquam aliquet.",
          status: "Active",
          date: "2020-01-01",
        },
        {
          name: "Ekaterina Tankova",
          description:
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor, nisl eget ultricies aliquam, nunc nisl aliquet nunc, vitae aliquam nisl nunc eu nisi. Sed vitae nisl eget nisl aliquam aliquet. Sed vitae nisl eget nisl aliquam aliquet.",
          status: "Active",
          date: "2020-01-01",
        },
        {
          name: "Tom Winter",
          description:
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor, nisl eget ultricies aliquam, nunc nisl aliquet nunc, vitae aliquam nisl nunc eu nisi. Sed vitae nisl eget nisl aliquam aliquet. Sed vitae nisl eget nisl aliquam aliquet.",
          status: "Active",
          date: "2020-01-01",
        },
        {
          name: "Sandra Jones",
          description:
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor, nisl eget ultricies aliquam, nunc nisl aliquet nunc, vitae aliquam nisl nunc eu nisi. Sed vitae nisl eget nisl aliquam aliquet. Sed vitae nisl eget nisl aliquam aliquet.",
          status: "Active",
          date: "2020-01-01",
        },
        {
          name: "Molly Summer",
          description:
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor, nisl eget ultricies aliquam, nunc nisl aliquet nunc, vitae aliquam nisl nunc eu nisi. Sed vitae nisl eget nisl aliquam aliquet. Sed vitae nisl eget nisl aliquam aliquet.",
          status: "Active",
          date: "2020-01-01",
        },
        {
          name: "Mark Winter",
          description:
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor, nisl eget ultricies aliquam, nunc nisl aliquet nunc, vitae aliquam nisl nunc eu nisi. Sed vitae nisl eget nisl aliquam aliquet. Sed vitae nisl eget nisl aliquam aliquet.",
          status: "Active",
          date: "2020-01-01",
        },
        {
          name: "Cindy Jones",
          description:
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor, nisl eget ultricies aliquam, nunc nisl aliquet nunc, vitae aliquam nisl nunc eu nisi. Sed vitae nisl eget nisl aliquam aliquet. Sed vitae nisl eget nisl aliquam aliquet.",
          status: "Active",
          date: "2020-01-01",
        },
      ];

      const customRender = (data) => {
        // Replace this with your custom rendering logic
        const tableBody = document.querySelector("#myTable tbody");
        tableBody.innerHTML = "";
        data.forEach((item) => {
          const row = document.createElement("tr");
          row.innerHTML = `
            <td>${item.name}</td>
            <td>${item.description}</td>
            <td>${item.status}</td>
            <td>${item.date}</td>
          `;
          tableBody.appendChild(row);
        });

        // Display pagination info
        const pageInfo = document.querySelector("#paginationInfo");
        pageInfo.textContent = `${easyTable.getShowingInfo()}`;
      };


      const easyTable = new EzyTables({
        data,
        perPage: 3,
        renderFunction: customRender,
        clientEnabled: true,
        client: {
            perPage: 3,
        }
      });

      const searchInput = document.querySelector("#searchInput");
      searchInput.addEventListener("input", () => {
        easyTable.setSearchDebounced(searchInput.value);
      });

      const prevButton = document.querySelector("#prevButton");
        prevButton.addEventListener("click", () => {
            easyTable.prevPage();
        });

        const nextButton = document.querySelector("#nextButton");
        nextButton.addEventListener("click", () => {
            easyTable.nextPage();
        });
    </script>
  </body>
</html>
Enter fullscreen mode Exit fullscreen mode

In this example, EzyTables is included as a JavaScript file, and an instance of EzyTables is created to manage the data table. The HTML structure is simple, and the logic is kept minimal, showcasing the ease of integrating EzyTables into a framework-agnostic context.

Conclusion

Data table management in web applications can be simplified and made more efficient with EzyTables. Its reactivity, simplicity, and customization options make it a valuable addition to your web development toolkit, regardless of the framework or library you're using. Give it a try, and you'll find that handling data tables has never been easier. EzyTables opens up new possibilities for efficient and elegant data table solutions in your web applications.

Head over to their documentation for more information and example here.

Top comments (0)