core
core copied to clipboard
Missing 'sort*' for FE Filter
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'.
In the CE and Module there is a selection for sorting field?
I mean the "FE filter CE", not the MM list elements.
You mean the filter options?
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.

@stefanheimes: small workaround:
add filter rule "Own SQL" as first in your filter set with
SELECT id FROM {{table}} ORDER BY <field> change
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:

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!
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...)
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.
...as alternative, we can use a input field for SELECT ... ORDER BY ZZ
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.
a problem of filter and attributes :-(
Why are these not the settings solving the problem?

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
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
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]
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