Jump to content
evanmcd

Sort by multiple fields in the admin?

Recommended Posts

Hi,

I wonder if there is any way to set a template to sort it's children by more than one column. I love that we can set this at either the template or page level, but I'd like to be able to sort by two columns as in SQL 'sort by column1, column2'

If there's not a solution, I'll consider doing a module for it.

Thanks.

Share this post


Link to post
Share on other sites

As far as I know this option isn't available in the back-end, but I remember Ryan wrote somewhere on this forum about the usage of more then one field to sort by in code. It should be something like this:

$pages->find("parent=$page, sort=field1, sort=field2");

Share this post


Link to post
Share on other sites

Yep, the API supports sorting with multiple values, but the admin UI doesn't (at least yet).

Share this post


Link to post
Share on other sites

This is correct. The admin UI doesn't let you select multiple fields to sort by yet. But your API calls can sort by as many fields a you want. It will use them in the order you specify them in the selector.

Share this post


Link to post
Share on other sites

Thanks all. I may need to hack a quick plugin together. I'll post back here if I do.

Share this post


Link to post
Share on other sites

i made a workaround (pretty dirty) for the same topic.

i set a value i want to sort by.

0 config

1 preview

2 statistic

3 formular

4 (here was my problem)

i have 6 tabs.

so i gave the tabs a value 1 - 6 and added that value to my sort mechanic.

i have a litle hook after save to set the position again.

$page->setOutputFormatting(false);

$page->ssort = 4 + $page->tab_position;

$page->save();

Share this post


Link to post
Share on other sites

Sorry to bring this back up but is this possible with a hook for the admin page tree?

I want to sort my pages in the admin, for a specific parent/child set up, by date then by status (so unpublished pages are at the top).

Any thoughts?

Share this post


Link to post
Share on other sites

Just look at the modules code. It's just a few handful of code and a single hook.

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By codevark
      The Minimal Site works fine, but if I try to login as admin, I have no idea what the credentials are.
      I did not do the "install" process myself. The OVA came with everything set up, but there's no mention of the PW admin credentials being set to some initial value.
      Wondering if anyone else has tried the Bitnami OVA and if there's a simple answer.
      --Pete
    • By vwatson
      I don't have any fontawesome icons in the admin section. Not sure what's wrong. They used to appear. I've tried all the user profiles and they're gone in all of them.
      Using the browser inspector tool, I see this message:
      Access to font at 'https://www.domain.com/wire/templates-admin/styles/font-awesome/fonts/fontawesome-webfont.ttf?v=4.7.0' from origin 'http://domain.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
      I'm not sure why this is occurring or how to fix it. Any help would be greatly appreciated. 
    • By Andi
      Getting a little deeper into the ProcessWire state-of-mind here. I seriously think I wouldn't have come back to webdev if it wasn't for this wonderful little gem of a CMS.
      I have an "Options" field added to all users on a site. If the user has anything other then "default" selected, I would like to show a permanent message in the admin like the one in the screenshot, only so that the user can't close it. As a friendly reminder that he changed that option from default to something crazy 🙂
      I've read up on how to send messages to users, but where would I hook into to make this show up all the time in the backend?
      https://processwire.com/api/ref/wire/message/
      Thanks in advance!

    • By BitPoet
      Here's a small new module that adds a "Manage tags" button to the template list, just like the field list already has.
      Easily add, remove and change tags for your templates.
      https://github.com/BitPoet/TemplateTagsEditList

    • By Noel Boss
      👋 PW Pros…
      I have some hooks that I need to bind at the init phase (or even __construct) and I was wondering, and I couldn't find a good and simple way to determine if I'm in the admin. Would be nice if there is a reliable short option to do so, but I can't seem to find one… Is there a coherent way to tell this no matter where I am?
      Right now, I use the following method inside one of my modules:
      public function isAdmin($page = null) { if ( strpos($this->input->url, $this->urls->admin) !== false || $this->process instanceof ProcessPageList || $this->process instanceof ProcessPageEdit || ($page instanceof Page && $page->rootParent->id == $this->config->adminRootPageID) ) { return true; } return false; } @ryan wouldn't it be nice to have something like wire()->isAdmin(); like wire()->user->isLoggedin(); to tell if we are in admin – very early on (probably even in __construct() phase of modules?
×
×
  • Create New...