Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expect return of new collection from custom sorting callback in NextrasDataSource #1140

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

dasim
Copy link
Contributor

@dasim dasim commented Aug 2, 2024

Nextras ORM collection are immutable. In custom sortable callback (set by setSortableCallback) we would typically call orderBy on the collection passed in first argument. But it would have no effect on the original collection in NextrasDataSource.

Example:

This would have no effect on ordering:

$grid->addColumnText('program', 'Program')->setSortable()->setSortableCallback(function (DbalCollection $collection, array $sorting) {
	$collection
		->resetOrderBy()
		->orderBy(['isElective' => $sorting['program'], 'program->name' => $sorting['program']]);
});

Before the suggested change, this would also have no effect on ordering.
But after the suggested change, this would achieve intended result:

$grid->addColumnText('program', 'Program')->setSortable()->setSortableCallback(function (DbalCollection $collection, array $sorting) {
	return $collection
		->resetOrderBy()
		->orderBy(['isElective' => $sorting['program'], 'program->name' => $sorting['program']]);
});

@radimvaculik
Copy link
Member

LGTM.

@f3l1x f3l1x merged commit 936e103 into contributte:master Aug 19, 2024
8 checks passed
@f3l1x
Copy link
Member

f3l1x commented Aug 19, 2024

👍

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

Successfully merging this pull request may close these issues.

3 participants