Skip to content

Commit

Permalink
sortDirection can now be applied to more than one column - fixes #151
Browse files Browse the repository at this point in the history
  • Loading branch information
uap-universe committed Dec 12, 2023
1 parent 63a71c7 commit 2168ec9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This document lists the changes introduced by this fork.

* Add Angular 17 support
* Add `hideTagList` setting to hide the tag list when columns are hidden
* The `sortDirection` column setting can now be applied to more than one column

## Version 3.1.1

Expand Down
1 change: 1 addition & 0 deletions projects/angular2-smart-table/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This document lists the changes introduced by this fork.

* Add Angular 17 support
* Add `hideTagList` setting to hide the tag list when columns are hidden
* The `sortDirection` column setting can now be applied to more than one column

## Version 3.1.1

Expand Down
22 changes: 8 additions & 14 deletions projects/angular2-smart-table/src/lib/lib/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,27 +258,21 @@ export class Grid {
}

prepareSource(source: DataSource): DataSource {
const initialSource = this.getInitialSort();
if (initialSource && initialSource['field'] && initialSource['direction']) {
source.setSort([initialSource], false);
}
source.setPaging(this.getPageToSelect(source), this.settings.pager?.perPage ?? 10, false);

source.refresh();
return source;
}

getInitialSort(): ISortConfig | null {
let sortConf: Array<ISortConfig> = [];
for (const column of this.getColumns()) {
if (column.isSortable && column.defaultSortDirection !== null) {
return {
sortConf.push({
field: column.id,
direction: column.defaultSortDirection,
compare: column.compareFunction,
};
});
}
}
return null;
source.setSort(sortConf, false);
source.setPaging(this.getPageToSelect(source), this.settings.pager?.perPage ?? 10, false);

source.refresh();
return source;
}

getSelectedItems(): Array<any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ <h3>Table Configuration</h3>
<td>
Sort table by this column with this direction by default.<br>
Applied only when <span class="highlight">sort</span> = true.
Note: multiple sort option is not supported yet, so sortDirection can be applied to only one column per table.
If sortDirection is specified for multiple columns, sort order will be from left to right.
</td>
</tr>
<tr>
Expand Down

0 comments on commit 2168ec9

Please sign in to comment.