pnpm add @payload-enchants/docs-reorder
Adds an option to re-order collection documents with drag n drop (almost like array/blocks items). Then on your front end you can query documents with applied sort by docOrder
field.
Plugin.mp4
In your payload.config.ts:
/// ....
import { docsReorder } from '@payload-enchants/docs-reorder';
export default buildConfig({
// ...
plugins: [
docsReorder({
collections: [{ slug: 'pages' }], // The feature will be enabled only for collections that are in this array.,
access: ({ req, data }) => {
// Optional, configure access for `saveChanges` endpoint, default: Boolean(req.user)
return req.user?.collection === 'admins';
},
}),
],
});
REST:
fetch('http://localhost:3000/api/examples?sort=docOrder').then((res) => res.json());
Local API:
payload.find({ collection: 'examples', sort: 'docOrder' });
GraphQL:
query {
Examples(sort: "docOrder") {
docs {
title
}
}
- Place this file to your src/scripts directory
- Change here list to your list of collection slugs with enabled plugin
const collections: (keyof GeneratedTypes['collections'])[] = ['docs-reoder-examples'];
- Run pnpm tsx ./src/scripts/docsReorderSetupScript.ts