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",
"version": "0.0.7",
"version": "0.0.8",
"description": "an internal use libary for handling data souces grid filtering sorting, add commands etc",
"keywords": [
"angular",

View File

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

View File

@ -1,3 +1,3 @@
<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>

View File

@ -10,25 +10,38 @@ export class DataSourceSortingComponent implements OnInit {
@Input() dataSource : IDataSource<any>;
@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() { }
ngOnInit(): void {
}
sorting(){
this.isSorting = true;
this.isAscending = !this.isAscending;
const existingSort = this.dataSource.sorts.find(t => t.path == this.path);
if (existingSort){
existingSort.ascending = (this.isAscending)? true : false;
}else{
if (!this.isSorting) {
this.dataSource.sorts.push({
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({
sorts: this.dataSource.sorts,
page: 1