Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Changing the order of related items, or creating lists of items with distinct order

788 views
Skip to first unread message

Nathan Wittstock

unread,
Jun 10, 2014, 6:45:19 PM6/10/14
to keyst...@googlegroups.com
So I'm trying to use KeystoneJS for a few new projects, but keep running into an issue that I haven't been able to solve: when creating categories or collections that have many items nested, is it possible to change their ordering?

For example, I have three models: Client, WorkItem, and WorkCategory. A WorkItem belongs to a single client, and multiple WorkCategories. When displaying a WorkCategory, I'd like to have the WorkItems appear in one order, and when displaying the Client, I'd like to see them in another order.

My Models:

var keystone = require('keystone');
var Types = keystone.Field.Types;

/**
 * Work Item Model
 * ===============
 */

var WorkItem = new keystone.List('WorkItem', { sortable: true });

WorkItem.add({
title: { type: Types.Text, required: true, index: true, initial: true },
description: { type: Types.Markdown, initial: true }
}, 'Assets', {
image: { type: Types.CloudinaryImage, note: 'Must be > 2048px on the long edge'},
thumbnail: { type: Types.CloudinaryImage, note: 'Must be > 800px square'},
mediaUrl: { type: Types.Url, label: 'Media URL' },
mediaInfo: { type: Types.Embedly, from: 'mediaUrl' }
}, 'Categorization', {
category: { type: Types.Relationship, ref: 'WorkCategory', many: true },
client: { type: Types.Relationship, ref: 'Client' }
});

/**
 * Registration
 */
WorkItem.defaultColumns = 'title, mediaUrl, client';
WorkItem.register();



var keystone = require('keystone');
var Types = keystone.Field.Types;

/**
 * Work Category Model
 * ===================
 */

var WorkCategory = new keystone.List('WorkCategory', { sortable: true });

WorkCategory.add({
name: { type: Types.Text, required: true, index: true, initial: true },
description: { type: Types.Markdown, initial: true }
});

WorkCategory.relationship({ path: 'items', ref: 'WorkItem', refPath: 'category' });

/**
 * Registration
 */
WorkCategory.defaultColumns = 'title';
WorkCategory.register();




var keystone = require('keystone');
var Types = keystone.Field.Types;

/**
 * Client Model
 * ============
 */

var Client = new keystone.List('Client', { sortable: true });

Client.add({
name: { type: Types.Text, required: true, index: true, initial: true },
description: { type: Types.Markdown, initial: true }
}, 'Identity', {
logo: { type: Types.CloudinaryImage, note: 'Must be > 400px on the long edge'},
thumbnail: { type: Types.CloudinaryImage, note: 'Must be > 800px square'},
url: { type: Types.Url, index: true }
});

Client.relationship({ path: 'work', ref: 'WorkItem', refPath: 'client' });

/**
 * Registration
 */
Client.defaultColumns = 'name, url';
Client.register();

Is there a way to solve this in Keystone, but still have a nice UI for an eventual non-technical user to manage this?

Thanks a bunch! Really hoping to move away from Django/Wordpress, but not have to write my own CMS UI!

—nate.

Paul Walker

unread,
Mar 11, 2015, 4:56:19 PM3/11/15
to keyst...@googlegroups.com
Bump. I'm looking for a solution to this problem as well. The documents mention a "sortable" attribute and a "sortContext" attribute, but I am unable to get this to work and can't find a working example.

Timon Davis

unread,
Apr 21, 2015, 2:34:45 AM4/21/15
to keyst...@googlegroups.com
+1  I am currently running into this issue as well.  Has anyone managed to find a work-around in the meanwhile?

Timon Davis

unread,
Apr 21, 2015, 2:21:09 PM4/21/15
to keyst...@googlegroups.com
Looks like there's something of a solution here: https://groups.google.com/forum/#!topic/keystonejs/wD_vwZQ9EfM

Reply all
Reply to author
Forward
0 new messages