Angular js sorting with comparator function
up vote
1
down vote
favorite
I need to sort my products by title - it works without any problem with orderBy:'+title'
inside my ng-repeat, but some of my products title contains numbers and I would like to move these products with numbers to the end.
I think I need to use this syntax now:
<div ng-repeat="product in products | filter : search | orderBy: '+title:false:localeSensitiveComparator' ">
and add the comparator function, but have no idea how to do it (what condition should I use inside the function):
$scope.localeSensitiveComparator = function(v1, v2) {
what condtion should I use here to detect and compare digits in the title?
// Compare numbers alphabetically, taking locale into account
return v1.value.localeCompare(v2.value);
};
Any help will be appreciated. Thanks.
I have this order now (with only orderBy: '+title')
https://prnt.sc/lk4no1
I would like this:
https://prnt.sc/lk4q2c
angularjs sorting
New contributor
add a comment |
up vote
1
down vote
favorite
I need to sort my products by title - it works without any problem with orderBy:'+title'
inside my ng-repeat, but some of my products title contains numbers and I would like to move these products with numbers to the end.
I think I need to use this syntax now:
<div ng-repeat="product in products | filter : search | orderBy: '+title:false:localeSensitiveComparator' ">
and add the comparator function, but have no idea how to do it (what condition should I use inside the function):
$scope.localeSensitiveComparator = function(v1, v2) {
what condtion should I use here to detect and compare digits in the title?
// Compare numbers alphabetically, taking locale into account
return v1.value.localeCompare(v2.value);
};
Any help will be appreciated. Thanks.
I have this order now (with only orderBy: '+title')
https://prnt.sc/lk4no1
I would like this:
https://prnt.sc/lk4q2c
angularjs sorting
New contributor
Show us example of your input and desired output
– Slava Utesinov
17 hours ago
I've added example screenshots.
– cooper33
17 hours ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I need to sort my products by title - it works without any problem with orderBy:'+title'
inside my ng-repeat, but some of my products title contains numbers and I would like to move these products with numbers to the end.
I think I need to use this syntax now:
<div ng-repeat="product in products | filter : search | orderBy: '+title:false:localeSensitiveComparator' ">
and add the comparator function, but have no idea how to do it (what condition should I use inside the function):
$scope.localeSensitiveComparator = function(v1, v2) {
what condtion should I use here to detect and compare digits in the title?
// Compare numbers alphabetically, taking locale into account
return v1.value.localeCompare(v2.value);
};
Any help will be appreciated. Thanks.
I have this order now (with only orderBy: '+title')
https://prnt.sc/lk4no1
I would like this:
https://prnt.sc/lk4q2c
angularjs sorting
New contributor
I need to sort my products by title - it works without any problem with orderBy:'+title'
inside my ng-repeat, but some of my products title contains numbers and I would like to move these products with numbers to the end.
I think I need to use this syntax now:
<div ng-repeat="product in products | filter : search | orderBy: '+title:false:localeSensitiveComparator' ">
and add the comparator function, but have no idea how to do it (what condition should I use inside the function):
$scope.localeSensitiveComparator = function(v1, v2) {
what condtion should I use here to detect and compare digits in the title?
// Compare numbers alphabetically, taking locale into account
return v1.value.localeCompare(v2.value);
};
Any help will be appreciated. Thanks.
I have this order now (with only orderBy: '+title')
https://prnt.sc/lk4no1
I would like this:
https://prnt.sc/lk4q2c
angularjs sorting
angularjs sorting
New contributor
New contributor
edited 17 hours ago
New contributor
asked 17 hours ago
cooper33
62
62
New contributor
New contributor
Show us example of your input and desired output
– Slava Utesinov
17 hours ago
I've added example screenshots.
– cooper33
17 hours ago
add a comment |
Show us example of your input and desired output
– Slava Utesinov
17 hours ago
I've added example screenshots.
– cooper33
17 hours ago
Show us example of your input and desired output
– Slava Utesinov
17 hours ago
Show us example of your input and desired output
– Slava Utesinov
17 hours ago
I've added example screenshots.
– cooper33
17 hours ago
I've added example screenshots.
– cooper33
17 hours ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
cooper33 is a new contributor. Be nice, and check out our Code of Conduct.
cooper33 is a new contributor. Be nice, and check out our Code of Conduct.
cooper33 is a new contributor. Be nice, and check out our Code of Conduct.
cooper33 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f53370928%2fangular-js-sorting-with-comparator-function%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
Show us example of your input and desired output
– Slava Utesinov
17 hours ago
I've added example screenshots.
– cooper33
17 hours ago