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

Change sorting icon after sorting #148

Open
pratiksha-chandel opened this issue Jan 8, 2018 · 1 comment
Open

Change sorting icon after sorting #148

pratiksha-chandel opened this issue Jan 8, 2018 · 1 comment

Comments

@pratiksha-chandel
Copy link

Hello There ,
I want to change icon on sorting .
1] As sending sorting will show ascending arrow .
2] As descending sorting will show descending arrow .
3] For filter data filter icon will display .
How can I do with this.
I have tried with this solution but not working fro me

import {Component, Input} from "@angular/core";
import {DataTable, SortEvent} from "angular2-datatable";

@component({
selector: 'mySorter',
template: <a style="cursor: pointer" (click)="sort()" class="text-nowrap"> <ng-content></ng-content> <span *ngIf="isSortedByMeAsc" class="glyphicon glyphicon-triangle-top" aria-hidden="true"></span> <span *ngIf="isSortedByMeDesc" class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span> <span *ngIf="!isSortedByMeAsc && !isSortedByMeDesc" class="glyphicon glyphicon-sort" aria-hidden="true"></span> </a>
})
export class MySorterComponent implements ngOnInit {
@input("by") sortBy: string;
isSortedByMeAsc: boolean = false;
isSortedByMeDesc: boolean = false;

public constructor(private mfTable: DataTable) {
}

public ngOnInit(): void {
    this.mfTable.onSortChange.subscribe((event: SortEvent) => {
        this.isSortedByMeAsc = (event.sortBy == this.sortBy && event.sortOrder == "asc");
        this.isSortedByMeDesc = (event.sortBy == this.sortBy && event.sortOrder == "desc");
    });
}

sort() {
    if (this.isSortedByMeAsc) {
        this.mfTable.setSort(this.sortBy, "desc");
    } else {
        this.mfTable.setSort(this.sortBy, "asc");
    }
}

}

Facing error : mfTable not a member of -- component .
this.mfTable.onSortChange : not a component member
this.mfTable.setSort(this.sortBy, "desc"); : not a component member and supplied parameter not match .

Any other solution for that? help please !

@pratiksha-chandel
Copy link
Author

screenerror

Facing this issue in console and data is not loading.

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

No branches or pull requests

1 participant