processwire / processwire-requests

ProcessWire feature requests.
39 stars 0 forks source link

Ability for PageTable sort and pages children sort to be the same #482

Open jlahijani opened 1 year ago

jlahijani commented 1 year ago

I've avoided using PageTable for many years because I haven't really needed it but also because of what I think is a hole in its current implementation.

My primary use case for PageTable is to be able to manage a pages children from within a page, rather than going to the page tree and editing the child pages of the parent page one-by-one.

In its current implementation, this works well however when it comes to the sort option, this is where I feel like there is a disconnect when the following settings are set for the field:

With those two options set, the PageTable field basically becomes a way to manage a pages children from within the page itself like I described above. However because the item pages in the page table can also be manually sorted, this sort that appears in the page table is DIFFERENT from the sort that would appear in the page tree (assuming the sort for the children in the tree is set to manual).

This leads to confusion when sorting in the page tree vs. sorting in the pagetable field because their sort states are independent of each other. Oftentimes I'll re-arrange pages from the page tree, but that won't be reflected in the parent page page table sort, or vice-versa.

My request is, if the above conditions are met, would it be possible to have a new option for a PageTable field that "syncs" (or whatever is the best strategy) the sort order between the page-tree sort and the pagetable field? That way whether one edits the sort from the tree or the pagetable field and queries pages in either manner, it returns the pages in the same sort order.

Does this make sense?

jlahijani commented 1 year ago

There was a discussion about this here: https://processwire.com/talk/topic/14709-set-order-of-pages-in-pagetable-field-via-api/?do=findComment&comment=132073

@Toutouwai @adrianbj

In the mean time, I have made it work the way I described using hooks and it's very effective. Time to use page table again after a 9 year hiatus. :)

To be more specific of my exact use case, imagine a page that's an ecommerce Variable Product (like T-shirt) with its children being the variations (Small Red, Small Blue, Medium Red, Medium Blue). By having a page table on the variable product page, you can sort the variant child pages from that page table field, as opposed to sorting them from the page tree. But sometimes I would sort them from the page tree and because the sorts of the page tree are not connected to the sorts of a page table, they will differ. The hooks I made fixes that no matter where you sort from. Would be nice if this was somehow native.