How to use system field 'ID' in filter function

You don’t need to speak chinese, it’s just the screenshots :slight_smile:

If you open the Properties of a dataset and try to add a filter, you cannot choose the ID (_id) field to filter on. It’s not present in the dropdown.

Would be nice to add a filter on ID, so that the filter doesn’t break if the Title field changes. For example if working with a collection that holds an enumeration.

As a workaround to this short-coming I have added an extra field called “publicID”, which can be filtered on. Next I add a data-hook BeforeInsert (and perhaps onBeforeUpdate to update existing items) to copy the hidden _id to publicID.

export function Specialisaties_beforeInsert ( item , context ) {
item . publicId = item . _id ;
return item ;
}

Kind of a dirty way of doing, but it’s the best I have come up with if you want to stay with using Dataset Settings instead of Page Code

1 Like