npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

datatable-customizer

v1.0.0

Published

A custom datatable initializer with additional features for filtering, exporting, and more.

Downloads

10

Readme

Custom DataTable Package

This package provides a customizable DataTable implementation with additional features like filtering, exporting, pagination, and search functionality. It is built on top of the popular DataTables jQuery plugin.

Features

  • Custom filtering logic
  • Export options (CSV, Excel, PDF, Copy, Print)
  • Pagination control
  • Search functionality with state saving
  • Dynamic length menu
  • Custom draw callbacks

Installation

  1. Clone the Repository:

    git clone https://github.com/ChandraHemant/datatable-customizer.git
    cd datatable-customizer
  2. Install Dependencies:

    Make sure you have jQuery and DataTables installed in your project. You can include them via CDN:

    <link rel="stylesheet" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.0.1/js/dataTables.buttons.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.0.1/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.0.1/js/buttons.print.min.js"></script>
    
     <!-- SumoSelect CSS and JS -->
    <link rel="stylesheet" href="https://github.com/ChandraHemant/datatable-customizer/blob/main/assets/sumoselect.css">
    <script src="https://github.com/ChandraHemant/datatable-customizer/blob/main/assets/jquery.sumoselect.min.js"></script>
    <script src="https://github.com/ChandraHemant/datatable-customizer/blob/main/assets/jquery.sumoselect.js"></script>
  3. Include Your Script:

    Add your custom JavaScript file to your HTML:

    <script src="path/to/your/datatable-customizer.js"></script>

Usage

  1. Initialize DataTable:

    You can initialize the DataTable by calling the datatable function with the necessary options:

    $(document).ready(function () {
        datatable({
            tableId: "yourTableId",  // The ID of your table element
            url: "/your-endpoint",    // URL for server-side data processing
            dataLength: '[data-length]',  // Selector for length menu element
            dataSearch: '[data-search]',  // Selector for search input element
            dataFilter: '[data-filter]',  // Selector for filter elements
            dataExport: '[data-export]',  // Selector for export buttons
            dataShowEntries: '[data-show-entries]',  // Selector for showing entries
            dataPagination: '[data-pagination]',  // Selector for pagination container
            dataStateSave: false,  // Save state (optional)
            drawCallback: function(settings) {
                console.log('DataTable Drawn');
                $('[data-bs-toggle="popover"]').popover('dispose');
                $('[data-bs-toggle="popover"]').popover({
                    trigger: 'hover'
                });
            }
        });
    });
  2. HTML Structure:

    Ensure your HTML structure includes the necessary elements:

    <table id="yourTableId" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Column 1</th>
                <th>Column 2</th>
                <th>Column 3</th>
                <!-- Add more columns as needed -->
            </tr>
        </thead>
        <tbody>
            <!-- Table data will be loaded via AJAX -->
        </tbody>
    </table>
    
    <!-- Elements for length, search, filter, export, show entries, and pagination -->
    <select data-length>
        <option value="5">5</option>
        <option value="10">10</option>
        <option value="25">25</option>
        <option value="-1">All</option>
    </select>
    <input type="text" data-search placeholder="Search here...">
    <!-- Add filter elements as needed -->
    <button data-export="pdf">Export PDF</button>
    <button data-export="csv">Export CSV</button>
    <div data-show-entries></div>
    <ul data-pagination></ul>
  3. Customizing Draw Callback:

    If you need to customize the table's behavior after each draw, modify the drawCallback function passed to the datatable function:

    drawCallback: function(settings) {
        console.log('Table redrawn with settings:', settings);
        // Add custom actions here
    }

License

This project is licensed under the MIT License.