1

Now I have a requirement to display the activity data in the activity list: Judging by the current time, the activities that are about to start are sorted in ascending order; the activities that are starting or have ended are sorted in descending order. Note: Upcoming data should come first, followed by past data.

I used the view's attachment to achieve this:

  1. The main view shows upcoming events
  2. The attachment shows the activity that is in progress or has ended

Now there are two more questions:

  1. The data of the main view and attachments are separated, but I actually want to display them together; for example: my list should display 4 pieces of data in one row, but the main view has only three pieces of data, and the result is that the data of the attachments does not follow the main The view displays, but starts to display on a new line, and the first line has only three pieces of data; what I want is that the first three pieces of the first line are the main view data, and the fourth piece is the first data of the attachment.
  2. Both the main view and the attachment have a paging bar, and I only want one paging bar, and the data of the main view and the attachment are merged and paginated.
1
  • At first I wanted to use HOOK_views_pre_build, HOOK_views_query_alter, HOOK_views_pre_execute to modify the query sql statement, but none of them took effect
    – River Zhao
    Commented Sep 16, 2022 at 8:12

1 Answer 1

0

I used another method to complete my needs, I don't need multiple views:

function MODULE_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  if ($view->id() == 'events') {
    $query->orderby = [];
    $query->addOrderBy(NULL, '(table.field_date<CURDATE())', 'ASC', 'all_date');
    $query->addOrderBy(NULL, '(greatest(table.field_date,CURDATE()))', 'ASC', 'now_date');
    $query->addOrderBy(NULL, '(least(CURDATE(),table.field_date))', 'DESC', 'old_date');
  }
}
enter code here

refer to: https://stackoverflow.com/questions/25892421/sort-records-by-future-asc-past-desc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.