Angular Material Sorting a number assending doesn't work
I am currently following the course "Angular Material" by Ajden on PluralSight and I am facing some weird behaviour with the sorting which on used with a table is not working completely. In the course, 3 columns are shown, the first column contains numbers and when I try to sort that column, nothing happens, the numbers stays in a assending way presented. When I sort the second column, which is a text column, the sorting works fine, asscending as well as descending. When I try to sort the number column again after I sorted the text column, the sorting is applied to the number column but always ascending, never descending. Am I missing something in my code or is this perhaps a bug in angular material? I am using the newest versions of Angular and Angular Material because I want to learn it that way.
This is the code I have so far related to the sorting:
The number sorting
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter"> </mat-form-field>
<table mat-table matSort [dataSource]="dataSource">
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef mat-sort-header>No.</th>
<td mat-cell *matCellDef="let note"> {{note.id}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="title">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Title</th>
<td mat-cell *matCellDef="let note"> {{note.title}} </td>
</ng-container>
<!-- Date Column -->
<ng-container matColumnDef="date">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Date</th>
<td mat-cell *matCellDef="let note"> {{note.date | date: 'd LLLL yyyy'}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> </table>
<mat-paginator [pageSize]="2" [pageSizeOptions]="[1, 2, 5]" showFirstLastButtons></mat-paginator>
Linking the sort element to the datasource
@ViewChild(MatSort)
sort: MatSort;
ngAfterContentInit(): void {
this.dataSource = new MatTableDataSource<Note>(this.notes);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
I also put the code I have so far in a git repository, which can be found here
angular sorting angular-material2
add a comment |
I am currently following the course "Angular Material" by Ajden on PluralSight and I am facing some weird behaviour with the sorting which on used with a table is not working completely. In the course, 3 columns are shown, the first column contains numbers and when I try to sort that column, nothing happens, the numbers stays in a assending way presented. When I sort the second column, which is a text column, the sorting works fine, asscending as well as descending. When I try to sort the number column again after I sorted the text column, the sorting is applied to the number column but always ascending, never descending. Am I missing something in my code or is this perhaps a bug in angular material? I am using the newest versions of Angular and Angular Material because I want to learn it that way.
This is the code I have so far related to the sorting:
The number sorting
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter"> </mat-form-field>
<table mat-table matSort [dataSource]="dataSource">
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef mat-sort-header>No.</th>
<td mat-cell *matCellDef="let note"> {{note.id}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="title">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Title</th>
<td mat-cell *matCellDef="let note"> {{note.title}} </td>
</ng-container>
<!-- Date Column -->
<ng-container matColumnDef="date">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Date</th>
<td mat-cell *matCellDef="let note"> {{note.date | date: 'd LLLL yyyy'}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> </table>
<mat-paginator [pageSize]="2" [pageSizeOptions]="[1, 2, 5]" showFirstLastButtons></mat-paginator>
Linking the sort element to the datasource
@ViewChild(MatSort)
sort: MatSort;
ngAfterContentInit(): void {
this.dataSource = new MatTableDataSource<Note>(this.notes);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
I also put the code I have so far in a git repository, which can be found here
angular sorting angular-material2
Your code is having issues. Can you please fix those? You can check errors in the browser console or terminal window.
– shhdharmen
Jan 18 at 12:36
Can you tell which issues you are facing? Cause when I execute ng serve in my command window, it is running fine and I am not having any errors in my browser console. Also ng build is running successful without any errors.
– Cornelis
Jan 18 at 12:55
Are you sure that you have pushed all of your changes to git? Try to run on stackblitz : stackblitz.com/github/Cornelis83/ps-angular-material. Below are the errors :ERROR in ./src/app/app.component.ts Module not found: Error: Can't resolve './app.component.scss' in 'D:tutorialsps-angular-materialsrcapp' ERROR in ./src/app/contactmanager/contactmanager-app.component.ts Module not found: Error: Can't resolve './contactmanager-app.component.scss' in 'D:tutorialsps-angular-materialsrcappcontactmanager' ERROR in ./src/app/contactmanager/components/...
– shhdharmen
Jan 18 at 13:19
Well, I actually used the upload functionality of github to get the code there, but I didn't know github refuses empty files that way and some of the .scss files were empty. So I fixed that issue.
– Cornelis
Jan 18 at 14:10
add a comment |
I am currently following the course "Angular Material" by Ajden on PluralSight and I am facing some weird behaviour with the sorting which on used with a table is not working completely. In the course, 3 columns are shown, the first column contains numbers and when I try to sort that column, nothing happens, the numbers stays in a assending way presented. When I sort the second column, which is a text column, the sorting works fine, asscending as well as descending. When I try to sort the number column again after I sorted the text column, the sorting is applied to the number column but always ascending, never descending. Am I missing something in my code or is this perhaps a bug in angular material? I am using the newest versions of Angular and Angular Material because I want to learn it that way.
This is the code I have so far related to the sorting:
The number sorting
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter"> </mat-form-field>
<table mat-table matSort [dataSource]="dataSource">
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef mat-sort-header>No.</th>
<td mat-cell *matCellDef="let note"> {{note.id}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="title">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Title</th>
<td mat-cell *matCellDef="let note"> {{note.title}} </td>
</ng-container>
<!-- Date Column -->
<ng-container matColumnDef="date">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Date</th>
<td mat-cell *matCellDef="let note"> {{note.date | date: 'd LLLL yyyy'}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> </table>
<mat-paginator [pageSize]="2" [pageSizeOptions]="[1, 2, 5]" showFirstLastButtons></mat-paginator>
Linking the sort element to the datasource
@ViewChild(MatSort)
sort: MatSort;
ngAfterContentInit(): void {
this.dataSource = new MatTableDataSource<Note>(this.notes);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
I also put the code I have so far in a git repository, which can be found here
angular sorting angular-material2
I am currently following the course "Angular Material" by Ajden on PluralSight and I am facing some weird behaviour with the sorting which on used with a table is not working completely. In the course, 3 columns are shown, the first column contains numbers and when I try to sort that column, nothing happens, the numbers stays in a assending way presented. When I sort the second column, which is a text column, the sorting works fine, asscending as well as descending. When I try to sort the number column again after I sorted the text column, the sorting is applied to the number column but always ascending, never descending. Am I missing something in my code or is this perhaps a bug in angular material? I am using the newest versions of Angular and Angular Material because I want to learn it that way.
This is the code I have so far related to the sorting:
The number sorting
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter"> </mat-form-field>
<table mat-table matSort [dataSource]="dataSource">
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef mat-sort-header>No.</th>
<td mat-cell *matCellDef="let note"> {{note.id}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="title">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Title</th>
<td mat-cell *matCellDef="let note"> {{note.title}} </td>
</ng-container>
<!-- Date Column -->
<ng-container matColumnDef="date">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Date</th>
<td mat-cell *matCellDef="let note"> {{note.date | date: 'd LLLL yyyy'}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> </table>
<mat-paginator [pageSize]="2" [pageSizeOptions]="[1, 2, 5]" showFirstLastButtons></mat-paginator>
Linking the sort element to the datasource
@ViewChild(MatSort)
sort: MatSort;
ngAfterContentInit(): void {
this.dataSource = new MatTableDataSource<Note>(this.notes);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
I also put the code I have so far in a git repository, which can be found here
angular sorting angular-material2
angular sorting angular-material2
asked Jan 18 at 12:25
CornelisCornelis
4922929
4922929
Your code is having issues. Can you please fix those? You can check errors in the browser console or terminal window.
– shhdharmen
Jan 18 at 12:36
Can you tell which issues you are facing? Cause when I execute ng serve in my command window, it is running fine and I am not having any errors in my browser console. Also ng build is running successful without any errors.
– Cornelis
Jan 18 at 12:55
Are you sure that you have pushed all of your changes to git? Try to run on stackblitz : stackblitz.com/github/Cornelis83/ps-angular-material. Below are the errors :ERROR in ./src/app/app.component.ts Module not found: Error: Can't resolve './app.component.scss' in 'D:tutorialsps-angular-materialsrcapp' ERROR in ./src/app/contactmanager/contactmanager-app.component.ts Module not found: Error: Can't resolve './contactmanager-app.component.scss' in 'D:tutorialsps-angular-materialsrcappcontactmanager' ERROR in ./src/app/contactmanager/components/...
– shhdharmen
Jan 18 at 13:19
Well, I actually used the upload functionality of github to get the code there, but I didn't know github refuses empty files that way and some of the .scss files were empty. So I fixed that issue.
– Cornelis
Jan 18 at 14:10
add a comment |
Your code is having issues. Can you please fix those? You can check errors in the browser console or terminal window.
– shhdharmen
Jan 18 at 12:36
Can you tell which issues you are facing? Cause when I execute ng serve in my command window, it is running fine and I am not having any errors in my browser console. Also ng build is running successful without any errors.
– Cornelis
Jan 18 at 12:55
Are you sure that you have pushed all of your changes to git? Try to run on stackblitz : stackblitz.com/github/Cornelis83/ps-angular-material. Below are the errors :ERROR in ./src/app/app.component.ts Module not found: Error: Can't resolve './app.component.scss' in 'D:tutorialsps-angular-materialsrcapp' ERROR in ./src/app/contactmanager/contactmanager-app.component.ts Module not found: Error: Can't resolve './contactmanager-app.component.scss' in 'D:tutorialsps-angular-materialsrcappcontactmanager' ERROR in ./src/app/contactmanager/components/...
– shhdharmen
Jan 18 at 13:19
Well, I actually used the upload functionality of github to get the code there, but I didn't know github refuses empty files that way and some of the .scss files were empty. So I fixed that issue.
– Cornelis
Jan 18 at 14:10
Your code is having issues. Can you please fix those? You can check errors in the browser console or terminal window.
– shhdharmen
Jan 18 at 12:36
Your code is having issues. Can you please fix those? You can check errors in the browser console or terminal window.
– shhdharmen
Jan 18 at 12:36
Can you tell which issues you are facing? Cause when I execute ng serve in my command window, it is running fine and I am not having any errors in my browser console. Also ng build is running successful without any errors.
– Cornelis
Jan 18 at 12:55
Can you tell which issues you are facing? Cause when I execute ng serve in my command window, it is running fine and I am not having any errors in my browser console. Also ng build is running successful without any errors.
– Cornelis
Jan 18 at 12:55
Are you sure that you have pushed all of your changes to git? Try to run on stackblitz : stackblitz.com/github/Cornelis83/ps-angular-material. Below are the errors :
ERROR in ./src/app/app.component.ts Module not found: Error: Can't resolve './app.component.scss' in 'D:tutorialsps-angular-materialsrcapp' ERROR in ./src/app/contactmanager/contactmanager-app.component.ts Module not found: Error: Can't resolve './contactmanager-app.component.scss' in 'D:tutorialsps-angular-materialsrcappcontactmanager' ERROR in ./src/app/contactmanager/components/...– shhdharmen
Jan 18 at 13:19
Are you sure that you have pushed all of your changes to git? Try to run on stackblitz : stackblitz.com/github/Cornelis83/ps-angular-material. Below are the errors :
ERROR in ./src/app/app.component.ts Module not found: Error: Can't resolve './app.component.scss' in 'D:tutorialsps-angular-materialsrcapp' ERROR in ./src/app/contactmanager/contactmanager-app.component.ts Module not found: Error: Can't resolve './contactmanager-app.component.scss' in 'D:tutorialsps-angular-materialsrcappcontactmanager' ERROR in ./src/app/contactmanager/components/...– shhdharmen
Jan 18 at 13:19
Well, I actually used the upload functionality of github to get the code there, but I didn't know github refuses empty files that way and some of the .scss files were empty. So I fixed that issue.
– Cornelis
Jan 18 at 14:10
Well, I actually used the upload functionality of github to get the code there, but I didn't know github refuses empty files that way and some of the .scss files were empty. So I fixed that issue.
– Cornelis
Jan 18 at 14:10
add a comment |
1 Answer
1
active
oldest
votes
in mat-sort-header you have to pass json key on which you want sort for example mat-sort-header="emp"
Thank you, as I said, I was following the course in a different (newer) version of angular and angular material and in the course, the author doesn't name the property to sort explicity and his sorting was working, even though the naming difference. But since Angular 6, for some reason (perhaps preventing magic code), the names must be equal else sorting doesn't work anymore. After rechecking the comments on pluralsight, someone else stated the same issue as well and appearently I missed it he first time.
– Cornelis
Jan 18 at 14:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54253994%2fangular-material-sorting-a-number-assending-doesnt-work%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
in mat-sort-header you have to pass json key on which you want sort for example mat-sort-header="emp"
Thank you, as I said, I was following the course in a different (newer) version of angular and angular material and in the course, the author doesn't name the property to sort explicity and his sorting was working, even though the naming difference. But since Angular 6, for some reason (perhaps preventing magic code), the names must be equal else sorting doesn't work anymore. After rechecking the comments on pluralsight, someone else stated the same issue as well and appearently I missed it he first time.
– Cornelis
Jan 18 at 14:24
add a comment |
in mat-sort-header you have to pass json key on which you want sort for example mat-sort-header="emp"
Thank you, as I said, I was following the course in a different (newer) version of angular and angular material and in the course, the author doesn't name the property to sort explicity and his sorting was working, even though the naming difference. But since Angular 6, for some reason (perhaps preventing magic code), the names must be equal else sorting doesn't work anymore. After rechecking the comments on pluralsight, someone else stated the same issue as well and appearently I missed it he first time.
– Cornelis
Jan 18 at 14:24
add a comment |
in mat-sort-header you have to pass json key on which you want sort for example mat-sort-header="emp"
in mat-sort-header you have to pass json key on which you want sort for example mat-sort-header="emp"
answered Jan 18 at 14:05
user10105289user10105289
161
161
Thank you, as I said, I was following the course in a different (newer) version of angular and angular material and in the course, the author doesn't name the property to sort explicity and his sorting was working, even though the naming difference. But since Angular 6, for some reason (perhaps preventing magic code), the names must be equal else sorting doesn't work anymore. After rechecking the comments on pluralsight, someone else stated the same issue as well and appearently I missed it he first time.
– Cornelis
Jan 18 at 14:24
add a comment |
Thank you, as I said, I was following the course in a different (newer) version of angular and angular material and in the course, the author doesn't name the property to sort explicity and his sorting was working, even though the naming difference. But since Angular 6, for some reason (perhaps preventing magic code), the names must be equal else sorting doesn't work anymore. After rechecking the comments on pluralsight, someone else stated the same issue as well and appearently I missed it he first time.
– Cornelis
Jan 18 at 14:24
Thank you, as I said, I was following the course in a different (newer) version of angular and angular material and in the course, the author doesn't name the property to sort explicity and his sorting was working, even though the naming difference. But since Angular 6, for some reason (perhaps preventing magic code), the names must be equal else sorting doesn't work anymore. After rechecking the comments on pluralsight, someone else stated the same issue as well and appearently I missed it he first time.
– Cornelis
Jan 18 at 14:24
Thank you, as I said, I was following the course in a different (newer) version of angular and angular material and in the course, the author doesn't name the property to sort explicity and his sorting was working, even though the naming difference. But since Angular 6, for some reason (perhaps preventing magic code), the names must be equal else sorting doesn't work anymore. After rechecking the comments on pluralsight, someone else stated the same issue as well and appearently I missed it he first time.
– Cornelis
Jan 18 at 14:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54253994%2fangular-material-sorting-a-number-assending-doesnt-work%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your code is having issues. Can you please fix those? You can check errors in the browser console or terminal window.
– shhdharmen
Jan 18 at 12:36
Can you tell which issues you are facing? Cause when I execute ng serve in my command window, it is running fine and I am not having any errors in my browser console. Also ng build is running successful without any errors.
– Cornelis
Jan 18 at 12:55
Are you sure that you have pushed all of your changes to git? Try to run on stackblitz : stackblitz.com/github/Cornelis83/ps-angular-material. Below are the errors :
ERROR in ./src/app/app.component.ts Module not found: Error: Can't resolve './app.component.scss' in 'D:tutorialsps-angular-materialsrcapp' ERROR in ./src/app/contactmanager/contactmanager-app.component.ts Module not found: Error: Can't resolve './contactmanager-app.component.scss' in 'D:tutorialsps-angular-materialsrcappcontactmanager' ERROR in ./src/app/contactmanager/components/...– shhdharmen
Jan 18 at 13:19
Well, I actually used the upload functionality of github to get the code there, but I didn't know github refuses empty files that way and some of the .scss files were empty. So I fixed that issue.
– Cornelis
Jan 18 at 14:10