1.0.0 • Published 3 years ago

ds-sorter v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

\

A web component for sorting elements

This web component follows the open-wc recommendations.

Installation

npm i ds-sorter

Usage

<script type="module">
  import 'ds-sorter/ds-sorter.js';
</script>

<ds-sorter>
  <!-- Put elements to be sorted here -->
</ds-sorter>

API

Properties

PropertyAttributeTypeDefaultDescription
bybystringA list of comma-separated rules to sort by in order of precedence. Specify attributes by name (e.g. "href"). If specifying a property, prepend with "." (e.g. ".innerText"). You can use nested properties as well (e.g. ".dataset.row"). Optionally, if you'd like to reverse a rule relative to the others, prepend a ">" (e.g. "href, >.innerText"). Finally, if you'd like to get a value of a descendant of the sorted element, wrap a selector in braces before the value and modifiers (e.g. {div label input} .checked).
comparator((a: HTMLElement, b: HTMLElement) => number) \| undefinedundefinedCustom comparison function for sorting
descendingdescendingbooleanfalseSort in descending order (else ascending is default)
randomrandombooleanfalseIf present, sorts randomly
rulesrulesRule[][{"key":"innerText"}]A list of rule objects to sort the elements by. Refer to Rule interface for properties.

Rule Interface

PropertyTypeDescription
keystring \| string[]Attribute name, or array representing a path of properties. (e.g. el.innerText -> 'innerText' or el.someObj.someChild.someGrandchild -> 'someObj', 'someChild', 'someGrandchild') Note: Changes to values of sorted attributes will trigger a re-sort. Changes to sorted properties will not.
selectorstring?Selector for descendant to get attribute/property off of
reversestring?If true, sort in reverse order relative to the global sort direction

Methods

MethodType
sort(): void

Events

EventDescription
ds-sortFired after a sort has completed

Slots

NameDescription
Content to sort

Contributing

Feel free to create tickets for bugs or feature requests, or to submit PRs. Please see CONTRIBUTING.md for more information about developing in ds-sorter.