Skip to content

Ui Listing sorting sometimes broken when SortOrderBuilder is used outside DataProvider #37731

Closed
@smartexcan

Description

@smartexcan

Preconditions and environment

  • Magento version: 2.0+ (affected class is \Magento\Framework\Api\Search\SearchCriteriaBuilder)

Steps to reproduce

  1. Create ui component listing
  2. Add some columns (id, name, etc)
  3. Add a Select column, which gets its options from a class that uses SortOrderBuilder.
  4. Add another non-select column after
  5. Apply sort to column before select column

Expected result

Columns before and after Select column should be sorted as intended when sort is applied.

Actual result

Columns before Select column (that uses SortOrderBuilder) don't get sort applied.
Columns after Select column do get sort applied.

Additional information

When using Magento\Framework\Api\SortOrderBuilder while loading a ui listing component (outside of the base DataProvider), trying to sort some columns might not work, depending on which column is being sorted.

If the column applies its sort order after the SortOrderBuilder is used, the sort will work.

The issue is in the \Magento\Framework\Api\Search\SearchCriteriaBuilder class.
Column ui components apply their sort order to the DataProvider, which adds it to the SearchCriteriaBuilder.

public function addSortOrder($field, $direction)
{
$this->sortOrderBuilder->setDirection($direction)
->setField($field);
return $this;
}

Because the SortOrder object is not created until the SearchCriteriaBuilder create() method is called, other code can use SortOrderBuilder and create an object from it, resulting in the fields from the Column no longer being present.

$this->data[SearchCriteria::SORT_ORDERS] = [$this->sortOrderBuilder->create()];

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Labels

Issue: needs updateAdditional information is require, waiting for responsePriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReported on 2.4.xIndicates original Magento version for the Issue report.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

  • Status

    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions