Skip to content

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

TagContributorsForksStargazersIssuesMIT License


hide-it

A vanilla javascript implementation of DataTables Responsive extension.
Report Bug · Request Feature

About The Project

project screen shot

This project provides an alternative to DataTables's responsive plugin. JQuery is still an dependency of DataTables and you may not want to include JQuery into your project. hide-it is completely written vanilla Javascript without any dependency to make your table's columns collapse when needed.

hide-it is "listener safe". When a column are "collapsed" and if the cell content is an HTML node (e.g. button), the content will be MOVED into a collapsible menu (not clone or copy) so that the listener binded on the DOM node will in theory be retained.

Althought this implementation is not efficient, it maximise the chance of retain the functionality and behaviour of third party reactive library like Alpine.js or HTMX, or custom event listener.

(back to top)

Getting Started

Include the source

You can go to the Releases page the download the source and include the source file to your project.

<linkhref=".../hide-it.css" rel="stylesheet"><scriptsrc=".../hide-it.js">

CDN

<linkhref="https://cdn.jsdelivr.net/gh/markmybytes/hide-it@<version>/dist/hide-it.min.css" rel="stylesheet"><scriptsrc="https://cdn.jsdelivr.net/gh/markmybytes/hide-it@<version>/dist/hide-it.min.js"></script>

Example

<!-- Specific Version --><linkhref="https://cdn.jsdelivr.net/gh/markmybytes/hide-it@0.0.1/dist/hide-it.min.css" rel="stylesheet"><scriptsrc="https://cdn.jsdelivr.net/gh/markmybytes/hide-it@0.0.1/dist/hide-it.min.js"></script><!-- Latest --><linkhref="https://cdn.jsdelivr.net/gh/markmybytes/hide-it@main/dist/hide-it.min.css" rel="stylesheet"><scriptsrc="https://cdn.jsdelivr.net/gh/markmybytes/hide-it@main/dist/hide-it.min.js"></script>

(back to top)

Usage

Initialisation

To make a table "responsive", you should create an instance of HideIt with the CSS selector to the target table.

constrpc=newHideIt("table");

Then, add the responsive class name to table headers. See Options for the default class names.

<thead><tr><th>ID</th><th>User Name</th><thclass="collapse-md">Email</th><thclass="collapse-lg">Action</th></tr></thead>

Methods

  1. process()

    Reparse the table. hide-it will gather the necessary information and manipulate the table to make the responsive functionality wokring. If new rows are added to the table, invoke this method.

  2. render()

    Show/hide columns based on the viewport width and responsive setting to columns

  3. hiddenClasses()

    Returns the hidden class names based on the current window width and breakpoints.

(back to top)

Options

hide-it allows you to customise the behaviour by supplying an setting object to HideIt.

constrpc=newHideIt("table",{});
  1. breakpoints

    Type
    Object<string,number>
    DescriptionClass names and its breakpoints (in pixel)
    Default
    {"collapse-xs": 576,"collapse-sm": 768,"collapse-md": 992,"collapse-lg": 1200,"collapse": Number.MAX_SAFE_INTEGER,}
  2. resizeTimeout

    Type
    number
    DescriptionDelay (in milliseconds) to rerender the table after a window resize event.
    Default 150

About

A vanilla javascript implementation of DataTables Responsive extension.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages