🎈 Welcome to the Marketplace β€” Explore and discover the ecosystem around DatoCMS, and share your own work with the community!

Record sorter (enity)

Drag-and-drop ordering of sortable and tree DatoCMS records, one language at a time

This is a Community Plugin!Β  Learn how create your own plugin, or copy and remix existing ones in our documentation

@partnersense/datocms-plugin-enity-record-sorter

A tree table of one model's records β€” title with folder and page icons, status, last updated β€” filtered by language and search, and reordered by drag and drop or with each row's move buttons; check several siblings to move them together. It opens in a dialog from a Sort in a table button above each sortable model's own collection, and as the Sort records page in the content sidebar. DatoCMS's own collection view refuses to reorder as soon as it is filtered ("You cannot reorder elements if the collection is filtered…"), which is the view editors work in on a multi-language project such as Bluestep's, with hundreds of pages per language.

It lists every model DatoCMS orders by hand β€” sortable and tree models (page first, if there is one). The language picker shows only when the project has more than one locale; All languages sorts the full list.

How a move works

DatoCMS orders records by position within one parent. Writing position: n to a record moves it to n and shifts the siblings in between by one; its publication status and version are untouched (checked on Bank2 stage: a published page moved and moved back stayed published, with no new version). Positions have gaps, so a move is computed relative to a neighbour in the filtered list (src/reorder.ts):

  • moved down, the record lands directly after the one it was dropped below; moved up, directly before the one it was dropped above;
  • records in other languages keep their place relative to the visible ones.

A move is one items.update call per record. Checked siblings move as one block in their current order (planBlockMove): the first lands next to its new neighbour, each next one directly after the previous, each write planned on the result of the last. A move takes the checked records under the moved record's parent; checked records anywhere can be published together. The page applies the same shift locally instead of reloading every record, and reloads if a write fails. Moves are one at a time (the controls are disabled while one saves).

Positions are absolute, so a move planned on numbers another editor has since changed would land off. Before each move the page reads back the current parent and position of every record under the parents involved (hasMoved, 100 per request); if any differ it reloads and asks for the move again instead of writing. A move made by someone else between that check and the writes is not caught.

Dragging works across the whole tree: over a row's top or bottom third the records land before or after it, over its middle they go into it (as its last children). Writing parent_id with position moves a record to another parent in one call (applyMoveTo; again no status or version change). Nothing can go into itself or below itself. The move buttons stay among siblings. A parent that isn't in the chosen language but has children that are is shown, greyed out, so the tree keeps its shape; it can't be moved from that language's list.

A record's languages are the keys of its localized fields' values, the same thing DatoCMS's "Locales" filter matches.

Files

FileResponsibility
src/main.tsxconnect(): the sidebar item and page, the button above each sortable collection, and the dialog it opens.
src/SorterPage.tsxThe table: model, language and search, the tree of sortable lists (dnd-kit), checkboxes, move buttons, status messages.
src/records.tsThe CMA: the editor's client, loading a model's records (parent, position, languages, title, slug, status), writing a position, checking for others' moves, publishing.
src/reorder.tsThe ordering rules: anchors, target positions, DatoCMS's shift, block moves, which records a language and search show, stale-place detection, publish request bodies. No imports; tested by the root pnpm test (src/__tests__/reorder.test.ts).
src/styles.cssLayout, from the CSS variables Canvas sets from the project's theme.

Accessibility

Every move works without a mouse: each row has to top, up, down and to bottom buttons, and the handle supports dnd-kit's keyboard drag (space to pick up, arrows, space to drop, escape to cancel) with screen-reader announcements that name the record. A keyboard drag drops before or after the record it ends over, never into it: its fixed steps mostly stop mid-row, where "into" would nest a record by accident. Focus stays on the button that moved a row (or its handle, once that button is disabled), and each move is announced in a polite live region. Sizes are in rem and rows wrap, so enlarged text doesn't clip.

Security

As the TinyMCE plugin: it runs in a sandboxed iframe and asks for the currentUserAccessToken permission, so it reads and writes as the editor using it β€” their role decides which records they can move. Whoever can publish this package can act as an editor; keep publishing in the workflow below, with 2FA on the npm account.

Develop, publish, roll out

Terminal window
cd plugins/datocms-record-sorter
pnpm install # its own workspace root: never touches the app's lockfile
pnpm dev # http://localhost:5173, for a private plugin's entry point URL
pnpm build # tsc + vite β†’ dist/

To try it before publishing, add a private plugin (Settings β†’ Plugins β†’ Add new β†’ Create new plugin) with http://localhost:5173 as its entry point, grant it "Access the current user's API token", and open Sort records in the content sidebar. Try it on a sandbox environment: moves are real writes.

  1. Bump version in package.json in the PR.
  2. After merge, run Actions β†’ Record sorter plugin β†’ Run workflow on the default branch. It publishes with npm trusted publishing and provenance. The first version is published by hand (npm publish --access public), then the repository and record-sorter-plugin.yml are added as the package's trusted publisher on npmjs.com.
  3. In each brand's project, install it from npm (Settings β†’ Plugins) or update it. Until then editors keep the previous version, which is also the rollback.
Subscribe to our newsletter! πŸ“₯
One update per month. All the latest news and sneak peeks directly in your inbox.
support@datocms.com Β©2026 Dato srl, all rights reserved P.IVA 06969620480