2

in a list view of extension news we need links which change the sort order and the sort direction. Is there a possibility to change both via get parameters? I unchecked the option "Disable override demand" and tried some combinations like

?tx_news_pi1[orderDirection]=asc
?tx_news_pi1[settings][orderDirection]=asc

but this doesnt work.

Thanks!

lisardo
  • 1,322
  • 16
  • 31

4 Answers4

3

tx_news_pi1[overwriteDemand][order]=title desc works for me

Georg Ringer
  • 7,779
  • 1
  • 16
  • 34
0

Maybe try:

tx_news_pi1[overwriteDemand][orderDirection]=asc

(while i am not really sure if orderDirection is correct, mayb check manual/code of that)

  • This no longer works (although it did previously). You have to use tx_news_pi1[overwriteDemand][order]=title desc as Georg Ringer already mentioned. – dominikweber Feb 04 '20 at 17:23
0

As far as I see there is no intuitive option to include sorting in the fluid-templates as all sorting is done on the level of TypoScript respectively FlexForm.

There are different options to enable sorting from frontend nevertheless:

  1. In TypoScript you set the sorting-parameters depending on the current URL-parameters, the easiest way would be to solve it by conditions, also you'd be free to define own parameters without sticking to the news-API.
    The URLs for sorting you should create in any case with a viewHelper that the cHash is always appended and calculated correct.

    TypoScript:

    #######
    ## Here you transfer the URL-parameters for sorting to the TypoScript-settings
    ## and also assure that only predefined values are accepted
    #######
    [globalVar = _GET|tx_news_pi1|orderBy = title]
        plugin.tx_news.settings.orderBy = title
    [globalVar = _GET|tx_news_pi1|orderBy = datetime]
        plugin.tx_news.settings.orderBy = datetime
    [globalVar = _GET|tx_news_pi1|orderBy = tstamp]
        plugin.tx_news.settings.orderBy = tstamp
    [globalVar = _GET|tx_news_pi1|orderBy = crdate]
        plugin.tx_news.settings.orderBy = crdate
    [global]
    
    [globalVar = _GET|tx_news_pi1|sort = desc]
        plugin.tx_news.settings.orderDirection = desc
    [else]
        plugin.tx_news.settings.orderDirection = asc
    [global]
    

    Fluid:

    <f:link.action action="list" addQueryString="&tx_news_pi1[orderBy]=title&tx_news_pi1[sort]=asc">Sort by title: asc</f:link.action>
    <f:link.action action="list" addQueryString="&tx_news_pi1[orderBy]=title&tx_news_pi1[sort]=desc">Sort by title: desc</f:link.action>
    

    This solution is not tested and it might be required still to adjust some things but in general it should be working.
    Cache-related issues are considered the same as with news-records in general, at least related to any required settings.
    Sorting by further fields requires further steps as stated here: https://docs.typo3.org/typo3cms/extensions/news/DeveloperManual/ExtendNews/ExtendFlexforms/Index.html#selectbox-sort-by

  2. Other individual solutions require programming in PHP and can base on hooks as well as on signals, the news-manual includes several chapters that might be useful:

  3. Furthermore it might be possible that there exist extensions that solve the sorting-job already but I'm not aware of it. You could search for news-related extensions. I could imagine that eventnews or dataviewer could be useful perhaps but I never checked that out and these extensions never might be useful at all for it.
    Also it's possible that you discover another useful extension on further search. If so, let us know ;-)

  4. Then there is still the option that somehow the desired behavior can be solved different, perhaps it's not or bad documented or I missed it.

Consider that you probably still have to tweak a bit if you use pagination and especially AJAX based pagination.

David
  • 5,882
  • 3
  • 33
  • 44
0

I found the reason for the problem and a work around.

the reason is the default sorting in the flexform: sorting by title. The GET-Parameter orderBy cannot overwrite the default sorting in the flexform. If you choose a default sorting in the flexform the orderBy parameter ist ignored but the orderDirection parameter works as expected. The result is confusing but consistent: the content ist always sorted by the default sorting but with different sortOrders.

After deleting the default sorting in the flexform all works as expected.

I presume this is a kind of a bug; i will post a question in the bug tracker of news.

lisardo
  • 1,322
  • 16
  • 31