Currently, the Field_collection module implements item weights using deltas, which to my understanding, is incorrect.
Part of this problem stems from the fact that field_collection items are loaded from the field_collection_item table instead of the field that it references.

Deltas are supposed to reference nothing more than the fact that more than one field instance exists.

For instance: I have a Profile2 field-collection called "Education". The source entity allows unlimited data in this field. The collection-item entity has several fields attached to it.

I noticed the .install doesn't provide a "weight" field for the field_collection_item. It also seems like this module removes all field-collection values for the present entity and re-inserts them using their "delta" as the order.

The reason this problem starts to crop up in views, is that the "delta" is a "field", not a pseudo-field like weights. So, when the view processes, "delta" is selected as data, and Views tries to use the field alias to handle sorting. The net effect is that Views selects delta information when it shouldn't be, and the items pulled from the DB don't match our expected results.

Comments

csdco’s picture

Also looking for this feature.

rerooting’s picture

Title:Views support: Sorting collection items is broken» Views: Field Collection Item weights not available for sorting
Category:bug» feature

Changed some of the issue information so that its more descriptive

webguy2000’s picture

I need this feature as well.

rerooting’s picture

Yes it looks like it's using delta, thus when items are removed or on edit, it looks like the array of field collection items is just reordered. I can see why they would do it this way (a very simple approach) but it makes views handlers very tricky.

Possibly, one could write a views handler that uses the delta and the host entity information to determine a 'weight' for any field collection item using one of the existing functions.

RobW’s picture

I think instead of creating a new way to accomplish an existing task, we should fix field collection by adding weights in addition to delta.

antonyanimator’s picture

Yeh I would really find having weights very useful. It would allow me to integrate into draggableviews

joelcollinsdc’s picture

so... there is no way to use views to print out items of a field collection in the order that they appear?

frhou’s picture

I did a view like this and found out an explanation:

In the database there is no weight stored, only the delta which is used to indicate the order of the elements.

So if you need to sort the field_collection items in your views' result by the order they are set, you'll need to use the delta as you'd use the weight.

CarbonPig’s picture

#8 worked for me. Thanks for the tip @milanith

mudsurfer’s picture

Hi milanith and CarbonPig - I'm feeling quite daft - but where did you find the delta field?
I have a view that just displays the content of a field collection (no other related data). But I cant find a way to display the view in the same order as they are set.
I've resorted to added a an extra "sort order" integer field on the field collection.

Watergate’s picture

I have just provided a comment to a similar question in the Field Collection Views module here

In this way no extra sort order fields are necessary.. just a required relationship to the parent entity.

Hope this can help you out.

antpowerWD’s picture

Issue summary:View changes

Can you explain this really simply, I don't fully understand the advanced stuff with Views and need to read up on it, but I have a grid of boxes using the field collection views module and I can't reorder any of them by weight. There are two views one for field collection itself and one for the 'boxes'. I've tried different configs, but nothing can enable them boxes to be re-ordered as my client would like.

Please help.....

Ant:-)

mareks’s picture

I only needed to add a relationship to my field collection item. AND I also had to check the "Require this relationship". I don't have anything in sorting criteria but my view still respects the row order (weight) in the collection.