Closed montabou closed 11 years ago
@montabou Gedmo/Sortable automatically handles ordering of entities saveing the order as integer value into field marked with @SortablePosition.
The sortable option in collection_table and collection_fieldset only enables some javascript code updateing a hidden field with an integer value. If user changes the order (by drag&drop UI) then the hidden values will be changed respectively.
Those hidden fields are automatically added to the form by the widget so they will be persisted when you submit your form.
If you don't use Gedmo -> then you have to use the value saved in that field to sort the collection. An OrderBy annotation should do the job.
@loostro I don't know if you notice my edit, but for now it works perfectly with collection_fieldset but does not work with collection_table
Does it throw any errors? Are you sure the collection is ordered? The widget itself just renders the items in the same order they are in the variable.
No, I have no error. I use admingenerator and it works perfectly with collection_fieldset so I guess my collection is well ordered as I've just have to change in the generator.yml :-) The position property is not hide using collection_table while it disappears with collection_fieldset
It should be hidden in both cases. Can you show a part of your generator.yml (for that field)?
fields:
titleSelections:
label: selection.title_selections.label
dbType: collection
formType: collection_fieldset
addFormOptions:
type: \...\...Bundle\Form\Type\TitleSelection\EditType
attr:
class: collection
allow_add: true
allow_delete: true
by_reference: false
sortable: true
options:
label: selection.title_selections.collection.label
data_class: ...\...Bundle\Entity\TitleSelection
It works with that. If I change collection_fieldset by collection_table it does not work.
I've checked the generated javascript code and there is no difference (between fieldset and table) and no error on firebug console. I will have other entities with ordered collection. When I will code them I will try and see if there is the same problem. For now, I have no idea why there is a problem. If you have any idea what I can check let me know otherwise, I will see later with other entities...
i'll keep this issue open and wait for more info from you
I've fixed it with this PR https://github.com/avocode/FormExtensions/pull/65
For more info, the position field was not hidden because of the accordion part
table{{ '#' ~ id }} > .collection > .collection-item > td > div > {{ 'div.' ~ sortable_field }}.control-group {
should have been replaced by
table{{ '#' ~ id }} > .collection > .collection-item > td > div > div > div > div > div > {{ 'div.' ~ sortable_field }}.control-group {
to consider all div direct children. I've replaced to select ascendant in PR
The drag'n'drop was not working because the main element id was missing. I've just added it to the td element tag. It works for me now
I do not use Gedmo\Sortable and don't know exactly how it works.
For now, With collection_table, sortable option has no effect With collection_fieldset, I can drag'n'drop elements but when saving it does not modify position correctly. In doc, it's written that it should begin by 1 for me it's 0 (that's not a big deal, but just to be sure)
I do not understand: Note: it is the developers job to that field for sortable behaviour in doc: https://github.com/avocode/FormExtensions/blob/master/Resources/doc/bootstrap-collection/overview.md
Does that mean that the query should sort before displaying elements ? Is this what Gedmo/Sortable does ? If so, how can I do this without Gedmo/Sortable, I did not find in admingenerator template ?
Edit: I've solved the sorting problem using @ORM\OrderBy({"position" = "ASC"}) So now, it works for collection_fieldset but not with collection_table