Maintain and organize the order of master data records

I followed the master data tutorial at

http://macresearch.org/cocoa-scientists-part-xxiii-itunes-ifying-core-data-app

The finished application displays data in an NSTableView. Is the ordering of the data preserved? And is there a way to allow permutations to be dragged into the order of records? I'm thinking of something that reminds me of how iTunes lets you drag and drop songs in a playlist.

+1


a source to share


3 answers


Core Data expects you to define your own collation using NSSortDescriptors, so you will have to add your own attribute to track a custom ordering index like a user. I have had good luck using KVO on the entity relationship key path (from the managed entity itself) to reorder as needed when new relationship entities are added or removed.



To handle regrouping, you will want to use the NSTableView drag and drop methods and reset the order index attribute as needed. The NSTableView documentation should explain this pretty well.

+4


a source


You will need to add a field that keeps track of the order of the items (could be an integer field). When you put objects in a table, you need to sort by this field.



When implementing drag and drop, you must update the order of the items.

0


a source


Instead of using an integer, I use the actual date and time (kind of timestamp) of creation. This will avoid duplicating your order field.

Then when I move the item up / down, I just change my order field. It has a relatively low processing cost.

When I fetch the data, I just select the items in the order of the am field.

0


a source







All Articles