An open API service indexing awesome lists of open source software.

https://github.com/markmead/alpinejs-sort

Sort data in Alpine JS without writing any JavaScript 🦜
https://github.com/markmead/alpinejs-sort

alpine-js alpinejs javascript javascript-sorting sortable sorting

Last synced: 10 months ago
JSON representation

Sort data in Alpine JS without writing any JavaScript 🦜

Awesome Lists containing this project

README

          

# Alpine JS Sort

Sort data in Alpine JS without writing any JavaScript 🦜

## Install

### With a CDN

```html

```

### With a Package Manager

```shell
yarn add -D alpinejs-sort

npm install -D alpinejs-sort
```

```js
import Alpine from 'alpinejs'
import sort from 'alpinejs-sort'

Alpine.plugin(sort)

Alpine.start()
```

## Examples

In all of these examples `asc` is the default, but this can be changed through
Alpine JS.

_You can move the `x-sort` onto the same element as the `x-data` if you wish._

### Simple Array

```html



Asc
Desc







```

Here we simply pass `asc` or `desc` as the array does not contain objects.

### Array of Objects

```html



Title (Asc)
Title (Desc)







```

Here we pass `asc.title` or `desc.title` as we want to sort on an object
property. This translate to:

> Sort by asc or desc order based on the value of `title`.

### Array of Objects (Nested)

```html



Please select
Title (Asc)
Title (Desc)







```

This is the same logic as the previous example.

_The nesting should go as far as you need! `item.title.main.translated.en`? Go
for it._

Here we pass `asc.title.main` or `desc.title.main` as we want to sort on a
nested object property. This translate to:

> Sort by asc or desc order based on the value of `main` in the `title` object.

## Stats

![](https://img.shields.io/bundlephobia/min/alpinejs-sort)
![](https://img.shields.io/npm/v/alpinejs-sort)
![](https://img.shields.io/npm/dt/alpinejs-sort)
![](https://img.shields.io/github/license/markmead/alpinejs-sort)