You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@raymondcamden/table-sorter

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@raymondcamden/table-sorter

A simple web component that adds sorting to a table. Given a simple table, wrap the contents with `<table-sort>`, load the component via a script tag, and the table will become sortable.

latest
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

<table-sorter>

A simple web component that adds sorting to a table. Given a simple table, wrap the contents with <table-sort>, load the component via a script tag, and the table will become sortable.

Check out the demo.

Usage

Your table must contain a <thead> and <tbody> tag pair.

There's only one optional argument, numeric, which represents the table columns that should be treated as numbers when sorted. Can be a comma-delimited list and column numbers begin with 1 because that just makes sense.

If your table cells make use of data-sortval, that value will be used instead of the contents of the cell. This lets you do things like having a numeric date value and a formatted string displayed. demo2.html shows an example of this.

Example

Note that numeric="4" here means to sort the fourth column, "Age", numerically.

<table-sort numeric="4">
<table>
	<thead>
		<tr>
			<th>Name</th>
			<th>Breed</th>
			<th>Gender</th>
			<th>Age</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>Luna</td>
			<td>Domestic Shorthair</td>
			<td>Female</td>
			<td>11</td>
		</tr>
		<!-- lots of rows -->
		<tr>
			<td>Apollo</td>
			<td>Persian</td>
			<td>Male</td>
			<td>3</td>
		</tr>	
	</tbody>

</table>
</table-sort>

Installation

Via npm or download table-sorter.js directly.

npm i @raymondcamden/table-sorter

History

DateChange
June 25, 2025Added data-sortval support and used DOM swapping instead of blowing away the table.

FAQs

Package last updated on 25 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts