Skip to content

Commit

Permalink
reapply sort on data source when items change
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed May 9, 2024
1 parent a7ec6b1 commit 8a08e47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions haxe/ui/data/ArrayDataSource.hx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ class ArrayDataSource<T> extends DataSource<T> {
handleChanged();
}

public override function sortCustom(fn:T->T->SortDirection->Int, direction:SortDirection = null) {
private override function handleSort(fn:T->T->SortDirection->Int, direction:SortDirection = null) {
_array.sort(fn.bind(_, _, direction));
if (_filteredArray != null) {
_filteredArray.sort(fn.bind(_, _, direction));
}
handleChanged();
}

private override function handleGetSize():Int {
Expand Down
12 changes: 12 additions & 0 deletions haxe/ui/data/DataSource.hx
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,25 @@ class DataSource<T> {

private function handleChanged() {
_changed = true;
if (_currentSortFn != null) {
handleSort(_currentSortFn, _currentSortDirection);
}
if (_allowCallbacks == true) {
_changed = false;
onInternalChange();
}
}

private function handleSort(fn:T->T->SortDirection->Int, direction:SortDirection = null) {
}

private var _currentSortFn:T->T->SortDirection->Int = null;
private var _currentSortDirection:SortDirection = null;
public function sortCustom(fn:T->T->SortDirection->Int, direction:SortDirection = null) {
_currentSortFn = fn;
_currentSortDirection = direction;
handleSort(fn, direction);
handleChanged();
}

public function sort(field:String = null, direction:SortDirection = null) {
Expand Down

0 comments on commit 8a08e47

Please sign in to comment.