-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
max_levels not being respected #50
Comments
I think max levels is use purely when nesting tree nodes together as a method of limiting the user from building an overly deep tree. See nestedSortable's doc for a better explanation. The max levels configuration option isn't used when rendering the What is it you want to do? |
I simply wanted to limit the depth of items being rendered. In this case, I just want to make 2 levels sortable. Is there any other way to make this? |
Unfortunately not without modifying the IndexAsSortable view. I'm reviewing the implementation now to see if there is a way to expose the logic behind tree traversal/rendering which would achieve your goal. |
What is your thought on the following API to control child rendering? ActiveAdmin.register Category do
sortable(
tree: true,
render_child?: -> (child) { child.depth < 2 }
)
index as: :sortable do
label :name
actions
end
end Here each child node is passed to the |
It's exactly what I need! |
Another downside to conditionally rendering individual children is that child sorting can become inconsistent for excluded children. Due to the way sorting is performed, which is done by sending the current displayed sort order to the server for persistence, if a child is missing it will become incorrectly sorted compared to its siblings. An alternative would be to check if a node's children should be rendered instead of a specific child. This avoids the issue of not rendering all of a child's siblings. Just more thoughts on the subject... 💡 |
An update to the proposed API would be to check if a node's children should be rendered... ActiveAdmin.register Category do
sortable(
tree: true,
render_children_of?: -> (node) { node.depth < 2 }
)
index as: :sortable do
label :name
actions
end
end |
I'm using sortable tree in a ActiveAdmin, in Rails 4.2, with the following:
But when visit the index, I see all levels, which are 3. Looking at the HTML, the data-* attributes were set appropriately:
Is there any problem with the options I passed?
The text was updated successfully, but these errors were encountered: