core icon indicating copy to clipboard operation
core copied to clipboard

Missing 'sort*' for FE Filter

Open stefanheimes opened this issue 12 years ago • 15 comments

We need a field do select on which fields the filter values are sorted. Now i have a list, sortetd by, i don't know what id, sorting, tstamp or what ever. But i want that all values are sorted by field 'xxx'.

stefanheimes avatar Mar 13 '13 12:03 stefanheimes

In the CE and Module there is a selection for sorting field?

backbone87 avatar Mar 13 '13 12:03 backbone87

I mean the "FE filter CE", not the MM list elements.

stefanheimes avatar Mar 13 '13 13:03 stefanheimes

You mean the filter options?

discordier avatar Mar 13 '13 22:03 discordier

Content Element - MetaModels FE Filter.

Chose MM, filter and everything else. Now go to the FE an select a value. How u see, all values sorted by sorting maybe. But i want that the values are sorted by the shown vlaue.

image

stefanheimes avatar Mar 14 '13 10:03 stefanheimes

@stefanheimes: small workaround:

add filter rule "Own SQL" as first in your filter set with SELECT id FROM {{table}} ORDER BY <field> change

zonky2 avatar Jun 14 '16 15:06 zonky2

I need to sort (and maybe filter) the options that are shown in the FE filter options. Exactly the purpose of @stefanheimes.

I wonder how to implement it the best way and created a mockup:

bildschirmfoto-2017-02-05-um-23 47 02

With this functionality implement (in the filter_select), you will be able to modify the filter options that are shown in the FE (my use case: I want to sort the list and don't want to show all filter options).

In addition, we can introduce a filter_sort which is doing nothing else than SELECT … ORDER BY ZZ.

Please give feedback!

richardhj avatar Feb 05 '17 22:02 richardhj

sounds good for me! ... and "kill two birds with one stone" so it's possible to filter e.g. all "Veranstalter" with property xy (has Catering, work only in Germany...)

zonky2 avatar Feb 06 '17 06:02 zonky2

Yeah! The only problem encountered to me: This will only work if the foreign table is a MetaModel (not a simple table) (because you can define a filter for MetaModels exclusively). Further feedback pls.

richardhj avatar Feb 06 '17 08:02 richardhj

...as alternative, we can use a input field for SELECT ... ORDER BY ZZ

zonky2 avatar Feb 06 '17 08:02 zonky2

I do not completely grasp how this solves your problem, you want to select a static filter here? What happens to the parameters in said filter? Will they revert to default? If not, how to define the values here? Like in the MOD/CE? What about language dependent values (We have this problem in the CE filter select already)?

Do not get me wrong, I like the attempt to ease usage and implementing such a feature. I simply do not want to open up yet another can of worms while we are yet undecided where to go fishing.

discordier avatar Feb 06 '17 16:02 discordier

a problem of filter and attributes :-(

zonky2 avatar Apr 25 '17 21:04 zonky2

Why are these not the settings solving the problem? sort

richardhj avatar Apr 25 '17 21:04 richardhj

e.g. at "simple lookup" and a FE widget as select box, we see a different sorting if "Remaining values only" checked or not... if checked, we have a sorted list als filter options but is unchecked is the list "unsorted"

look at https://github.com/MetaModels/core/blob/master/src/MetaModels/Attribute/BaseSimple.php#L97 and different ORDER BY https://github.com/MetaModels/core/blob/master/src/MetaModels/Attribute/BaseSimple.php#L105

zonky2 avatar Apr 29 '17 15:04 zonky2

e.g. https://github.com/MetaModels/core/blob/master/src/MetaModels/Attribute/BaseSimple.php#L87-L111

    public function getFilterOptions($idList, $usedOnly, &$arrCount = null)
    {
        $strCol            = $this->getColName();
        $strOrderDirection = $this->getOrderDirection();
        if ($idList) {
            $objRow = $this->getMetaModel()->getServiceContainer()->getDatabase()
                ->prepare(
                    'SELECT ' . $strCol . ', COUNT(' . $strCol . ') as mm_count
                    FROM ' . $this->getMetaModel()->getTableName() .
                    ' WHERE id IN (' . $this->parameterMask($idList) . ')
                    GROUP BY ' . $strCol . '
-                   ORDER BY FIELD(id,' . $this->parameterMask($idList). ')'
+                   ORDER BY ' . ($strOrderDirection ? $strOrderDirection : $strCol)
                )
                ->execute(array_merge($idList, $idList));
        } elseif ($usedOnly) {
            $objRow = $this->getMetaModel()->getServiceContainer()->getDatabase()->execute(
                'SELECT ' . $strCol . ', COUNT(' . $strCol . ') as mm_count
                FROM ' . $this->getMetaModel()->getTableName() . '
                GROUP BY ' . $strCol . '
-               ORDER BY ' . $strCol
+               ORDER BY  ' . ($strOrderDirection ? $strOrderDirection : $strCol)
            );
        } else {
            // We can not do anything here, must be handled by the derived attribute class.
            return array();
        }
        $arrResult = array();
        while ($objRow->next()) {
            if (is_array($arrCount)) {
                $arrCount[$objRow->$strCol] = $objRow->mm_count;
            }
            $arrResult[$objRow->$strCol] = $objRow->$strCol;
        }
        return $arrResult;
    }

$this->getOrderDirection() same value like $strDirection https://github.com/MetaModels/core/blob/master/src/MetaModels/Attribute/BaseSimple.php#L128

zonky2 avatar May 10 '17 14:05 zonky2

at this time it´s not possible to change this - we should use own interface to config the filter... may be at MM 3.x

[MM-call 30.05.2017]

zonky2 avatar May 30 '17 19:05 zonky2

We add in MM 2.2 an otion to sort like natural sort - this is important if the filter values come from the same MM-table

zonky2 avatar Feb 10 '23 21:02 zonky2