Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 1.1 KB

README.md

File metadata and controls

38 lines (26 loc) · 1.1 KB

Dentropize

Javascript function to sort tables

Demo

GitHub Pages

Install

  • Copy in the dentropize.js to your project or use jsDelivr.
    • vendor/javascript/dentropize.js for Rails.
  • Import the function
  • Add to the appropriate event for your framework.
  • Example below is a Rails 7 app using Importmaps and Turbo
// app/javascript/application.js

import dentropize from "dentropize"
document.addEventListener('turbo:load', dentropize);
# config/importmap.rb

pin "dentropize", to: "dentropize.js"

Usage

  • Add the CSS class "sortable" to your table.
  • To sort by a hidden value use "data-sort"
    • <td data-sort="5">five</td>

Notes

  • This code is essentially a heavily modified sortable made to work like jquery tablesorter but only the parts you really REALLY need.
  • There is no requirement for a <tbody> instead any rows NOT in a <thead> or <tfoot> are sorted.