Skip to content

Sorting: resolve sortable callback from the currently sorted columns - #1326

Open
radimvaculik wants to merge 1 commit into
masterfrom
radimvaculik/custom-sort-callback-of-a-previously-sorted-colu
Open

radimvaculik wants to merge 1 commit into
masterfrom
radimvaculik/custom-sort-callback-of-a-previously-sorted-colu

Conversation

@radimvaculik

@radimvaculik radimvaculik commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Refs #1325.

Datagrid::$sortCallback kept a copy of the sorted column's callback, filled in from three places (handleSort(), findStorageValues(), and a fallback in createSorting() that used the last column in the loop). handleSort() never reset it, so calling it twice on the same instance (sort by a column with setSortableCallback(), then by a plain one) passed the old callback to the data source. In a real app every request builds a new grid, so this doesn't happen in practice (see the reporter's analysis in #1325). The stored copy is still redundant, because the callback can always be worked out from the sorted columns.

createSorting() now resolves the callback from the columns in the current sort (the first column with a callback wins), and the property is removed. An explicitly passed $sortCallback argument still takes precedence.

Behavior change: when several sorted columns have callbacks, the first column's callback is used instead of the last one's.

Note: the protected $sortCallback property is removed, which affects subclasses that read or set it.

This touches the same code as #1320; whichever is merged second will need a rebase.

Validation: DatagridTest::testSortCallbackOfPreviouslySortedColumnIsNotApplied sorts twice on one instance and loads data through a filtered export. make tests, make phpstan, make cs pass.

Uložený Datagrid::$sortCallback se při přepnutí řazení nevynuloval, takže se callback dříve řazeného sloupce aplikoval na sloupec bez callbacku. createSorting() teď callback vždy zjistí z řazených sloupců (closes #1325).
@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.44444% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.19%. Comparing base (b268295) to head (ee6d0e4).

Files with missing lines Patch % Lines
src/Datagrid.php 44.44% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1326      +/-   ##
==========================================
+ Coverage   55.75%   56.19%   +0.44%     
==========================================
  Files          65       65              
  Lines        3024     3018       -6     
==========================================
+ Hits         1686     1696      +10     
+ Misses       1338     1322      -16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant