-
Notifications
You must be signed in to change notification settings - Fork 88
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
Ability to specify whether null records should be first or last when sorting. #296
Conversation
… beginning or the end of the result set when sorting
Codecov Report
@@ Coverage Diff @@
## master #296 +/- ##
==========================================
+ Coverage 95.74% 95.76% +0.01%
==========================================
Files 5 5
Lines 235 236 +1
Branches 79 80 +1
==========================================
+ Hits 225 226 +1
Misses 9 9
Partials 1 1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
This is what the config looks like now return paginate(query, dataRepository, {
sortableColumns: ['id', 'name', 'color', 'age'],
nullSort: 'last', // <--- new field
searchableColumns: ['name', 'color', 'age'],
defaultSortBy: [['id', 'DESC']],
filterableColumns: {
age: [FilterOperator.GTE, FilterOperator.LTE],
},
}); Initially I thought it would be useful to have it in the query instead, like:
But it seems more fitting for it to be a config, as it's not something I imagine you'd change often. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with everything.
LGTM 🌟
🎉 This PR is included in version 4.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@Elbarae1921 Ah sorry, just looking at it after merging:
|
@ppetzold my bad. Initially, I set Sure, I can. Would have to open a new PR tho right? |
Yes pls :) |
Version 4.2.0 sadly breaks pagination when using MySQL. Invalid syntax NULLS FIRST/LAST is not stripped out by TypeORM for databases like MySQL. Reverted back to 4.1.0 for now. |
@Elbarae1921 Can you remove the default then / only append to query if set? And add in comment/README that not all database types are supported? |
… beginning or the end of the result set when sorting (ppetzold#296)
Closes #267.
I believe this is the official "typeorm" way of doing it (typeorm/typeorm#685). I think it doesn't work on all databases but that's for the typeorm project to worry about.
I added a new test closure for the new functionality, LMK if maybe there should be more, I also updated the readme.