sorting fix

This commit is contained in:
David Lebee 2021-05-26 13:13:07 -04:00
parent 5c3fcced08
commit e2995ff932
4 changed files with 25 additions and 14 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@poweredsoft/ngx-bootstrap", "name": "@poweredsoft/ngx-bootstrap",
"version": "0.0.7", "version": "0.0.8",
"description": "an internal use libary for handling data souces grid filtering sorting, add commands etc", "description": "an internal use libary for handling data souces grid filtering sorting, add commands etc",
"keywords": [ "keywords": [
"angular", "angular",

View File

@ -53,6 +53,4 @@ export class CommandModalDirective {
}); });
} }
} }

View File

@ -1,3 +1,3 @@
<span> <span>
<span class="caret dropdown-toggle" [class.not-sorting-state]="!isSorting" [class.sort-desc]="!isAscending" (click)="sorting()"></span> <span class="caret dropdown-toggle" [class.not-sorting-state]="!isSorting" [class.sort-desc]="isAscending" (click)="sorting()"></span>
</span> </span>

View File

@ -10,25 +10,38 @@ export class DataSourceSortingComponent implements OnInit {
@Input() dataSource : IDataSource<any>; @Input() dataSource : IDataSource<any>;
@Input() path:string; @Input() path:string;
isSorting: boolean =false;
isAscending:boolean = false;
get sort() {
return this.dataSource.sorts.find(t => t.path == this.path);
}
get isSorting() {
return this.sort ? true : false;
}
get isAscending() {
return !this.isSorting ? true : this.sort.ascending;
}
constructor() { } constructor() { }
ngOnInit(): void { ngOnInit(): void {
} }
sorting(){ sorting(){
this.isSorting = true;
this.isAscending = !this.isAscending; if (!this.isSorting) {
const existingSort = this.dataSource.sorts.find(t => t.path == this.path);
if (existingSort){
existingSort.ascending = (this.isAscending)? true : false;
}else{
this.dataSource.sorts.push({ this.dataSource.sorts.push({
path: this.path, path: this.path,
ascending: (this.isAscending)? true : false ascending: true
}) });
} else if(this.isSorting && this.isAscending) {
this.sort.ascending = false;
} else {
this.dataSource.sorts = this.dataSource.sorts.filter(t => t.path != this.path);
} }
this.dataSource.query({ this.dataSource.query({
sorts: this.dataSource.sorts, sorts: this.dataSource.sorts,
page: 1 page: 1