{"id":16788786,"url":"https://github.com/markmead/alpinejs-sort","last_synced_at":"2025-04-10T23:25:04.387Z","repository":{"id":190623292,"uuid":"613895273","full_name":"markmead/alpinejs-sort","owner":"markmead","description":"Sort data in Alpine JS without writing any JavaScript 🦜","archived":false,"fork":false,"pushed_at":"2025-03-07T08:14:16.000Z","size":20,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T20:12:30.598Z","etag":null,"topics":["alpine-js","alpinejs","javascript","javascript-sorting","sortable","sorting"],"latest_commit_sha":null,"homepage":"https://js.hyperui.dev/examples/sort","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markmead.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["markmead"]}},"created_at":"2023-03-14T13:40:20.000Z","updated_at":"2025-03-07T08:14:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"712617ee-55e8-4bf9-b277-37ad82510859","html_url":"https://github.com/markmead/alpinejs-sort","commit_stats":null,"previous_names":["markmead/alpinejs-sort"],"tags_count":0,"template":false,"template_full_name":"markmead/alpinejs-plugin-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-sort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-sort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-sort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-sort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markmead","download_url":"https://codeload.github.com/markmead/alpinejs-sort/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248313622,"owners_count":21082886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alpine-js","alpinejs","javascript","javascript-sorting","sortable","sorting"],"created_at":"2024-10-13T08:24:46.863Z","updated_at":"2025-04-10T23:25:04.368Z","avatar_url":"https://github.com/markmead.png","language":"JavaScript","funding_links":["https://github.com/sponsors/markmead"],"categories":[],"sub_categories":[],"readme":"# Alpine JS Sort\n\nSort data in Alpine JS without writing any JavaScript 🦜\n\n## Install\n\n### With a CDN\n\n```html\n\u003cscript\n  defer\n  src=\"https://unpkg.com/alpinejs-sort@latest/dist/sort.min.js\"\n\u003e\u003c/script\u003e\n\n\u003cscript defer src=\"https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js\"\u003e\u003c/script\u003e\n```\n\n### With a Package Manager\n\n```shell\nyarn add -D alpinejs-sort\n\nnpm install -D alpinejs-sort\n```\n\n```js\nimport Alpine from 'alpinejs'\nimport sort from 'alpinejs-sort'\n\nAlpine.plugin(sort)\n\nAlpine.start()\n```\n\n## Examples\n\nIn all of these examples `asc` is the default, but this can be changed through\nAlpine JS.\n\n_You can move the `x-sort` onto the same element as the `x-data` if you wish._\n\n### Simple Array\n\n```html\n\u003cdiv x-data=\"{ items: ['D post', 'A post', 'C post', 'B post'], type: 'asc' }\"\u003e\n  \u003cselect x-model=\"type\"\u003e\n    \u003coption value=\"asc\"\u003eAsc\u003c/option\u003e\n    \u003coption value=\"desc\"\u003eDesc\u003c/option\u003e\n  \u003c/select\u003e\n\n  \u003cul x-sort.items=\"type\"\u003e\n    \u003ctemplate x-for=\"item in items\"\u003e\n      \u003cli x-text=\"item\"\u003e\u003c/li\u003e\n    \u003c/template\u003e\n  \u003c/ul\u003e\n\u003c/div\u003e\n```\n\nHere we simply pass `asc` or `desc` as the array does not contain objects.\n\n### Array of Objects\n\n```html\n\u003cdiv\n  x-data=\"{\n      items: [\n        { title: 'D post' },\n        { title: 'A post' },\n        { title: 'C post' },\n        { title: 'B post' }\n      ],\n      type: 'asc.title'\n    }\"\n\u003e\n  \u003cselect x-model=\"type\"\u003e\n    \u003coption value=\"asc.title\"\u003eTitle (Asc)\u003c/option\u003e\n    \u003coption value=\"desc.title\"\u003eTitle (Desc)\u003c/option\u003e\n  \u003c/select\u003e\n\n  \u003cul x-sort.items=\"type\"\u003e\n    \u003ctemplate x-for=\"item in items\"\u003e\n      \u003cli x-text=\"item.title\"\u003e\u003c/li\u003e\n    \u003c/template\u003e\n  \u003c/ul\u003e\n\u003c/div\u003e\n```\n\nHere we pass `asc.title` or `desc.title` as we want to sort on an object\nproperty. This translate to:\n\n\u003e Sort by asc or desc order based on the value of `title`.\n\n### Array of Objects (Nested)\n\n```html\n\u003cdiv\n  x-data=\"{\n    items: [\n        { title: { main: 'D post', sub: 'D' } },\n        { title: { main: 'A post', sub: 'A' } },\n        { title: { main: 'C post', sub: 'C' } },\n        { title: { main: 'B post', sub: 'B' } }\n    ],\n    type: 'asc.title.main'\n  }\"\n\u003e\n  \u003cselect x-model=\"type\"\u003e\n    \u003coption value=\"\"\u003ePlease select\u003c/option\u003e\n    \u003coption value=\"asc.title.main\"\u003eTitle (Asc)\u003c/option\u003e\n    \u003coption value=\"desc.title.main\"\u003eTitle (Desc)\u003c/option\u003e\n  \u003c/select\u003e\n\n  \u003cul x-sort.items=\"type\"\u003e\n    \u003ctemplate x-for=\"item in items\"\u003e\n      \u003cli x-text=\"item.title.main\"\u003e\u003c/li\u003e\n    \u003c/template\u003e\n  \u003c/ul\u003e\n\u003c/div\u003e\n```\n\nThis is the same logic as the previous example.\n\n_The nesting should go as far as you need! `item.title.main.translated.en`? Go\nfor it._\n\nHere we pass `asc.title.main` or `desc.title.main` as we want to sort on a\nnested object property. This translate to:\n\n\u003e Sort by asc or desc order based on the value of `main` in the `title` object.\n\n## Stats\n\n![](https://img.shields.io/bundlephobia/min/alpinejs-sort)\n![](https://img.shields.io/npm/v/alpinejs-sort)\n![](https://img.shields.io/npm/dt/alpinejs-sort)\n![](https://img.shields.io/github/license/markmead/alpinejs-sort)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmead%2Falpinejs-sort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkmead%2Falpinejs-sort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmead%2Falpinejs-sort/lists"}