Sort by multiple criteria
up vote
0
down vote
favorite
I have a column that looks like this :
0 // Red colored
0 // Red colored
0 (1) // Orange colored
0 (2) // Red colored
0 // Orange colored
0 // Red colored
0 (24) // Orange colored
0 (4) // Red colored
0 // Orange colored
0 (3) // Orange colored
1
1
1 (7)
2
2 (3)
2
... etc
I would get the following order :
0 // Red colored
0 // Red colored
0 // Red colored
0 (24) // Red colored
0 (4) // Red colored
0 (2) // Red colored
0 // Orange colored
0 // Orange colored
0 (4) // Orange colored
0 (1) // Orange colored
1
1
1 (7)
2
2 (3)
2
... etc
I want to order this column in datatables using these 3 criteria : first order by number (0's), then by color (red first), then by number un parantheses (the highest first).
I've got in each data-order
the following format : 0r24
which means the first number is zero, the color is red, the number in the parantheses is 24. Repeat for all others.
I tried to play with the columnDefs
attribute of Datatables to get my result by doing the following :
"columnDefs": [
{
"type": "num-fmt",
"targets": 7
}, {
"targets": [7],
"render": function ( data, type, row, meta ) {
return type === 'sort' ?
row[7]['@data-order'].replace(/r/g,'0').replace(/o/g,'1') : row[7]['@data-order'];
}
}
]
Here I am trying to replace the letters o
and r
with 0
and 1
to be able to have an all numeric value for it to order upon, but it doesn't work. Any idea how to make this work and do the following as I explained?
javascript jquery datatables
New contributor
add a comment |
up vote
0
down vote
favorite
I have a column that looks like this :
0 // Red colored
0 // Red colored
0 (1) // Orange colored
0 (2) // Red colored
0 // Orange colored
0 // Red colored
0 (24) // Orange colored
0 (4) // Red colored
0 // Orange colored
0 (3) // Orange colored
1
1
1 (7)
2
2 (3)
2
... etc
I would get the following order :
0 // Red colored
0 // Red colored
0 // Red colored
0 (24) // Red colored
0 (4) // Red colored
0 (2) // Red colored
0 // Orange colored
0 // Orange colored
0 (4) // Orange colored
0 (1) // Orange colored
1
1
1 (7)
2
2 (3)
2
... etc
I want to order this column in datatables using these 3 criteria : first order by number (0's), then by color (red first), then by number un parantheses (the highest first).
I've got in each data-order
the following format : 0r24
which means the first number is zero, the color is red, the number in the parantheses is 24. Repeat for all others.
I tried to play with the columnDefs
attribute of Datatables to get my result by doing the following :
"columnDefs": [
{
"type": "num-fmt",
"targets": 7
}, {
"targets": [7],
"render": function ( data, type, row, meta ) {
return type === 'sort' ?
row[7]['@data-order'].replace(/r/g,'0').replace(/o/g,'1') : row[7]['@data-order'];
}
}
]
Here I am trying to replace the letters o
and r
with 0
and 1
to be able to have an all numeric value for it to order upon, but it doesn't work. Any idea how to make this work and do the following as I explained?
javascript jquery datatables
New contributor
Are the actual source values"Red colored"
and"Orange colored"
?
– axelduch
Nov 19 at 13:52
@axelduch yes, my comment means that the color of the zero is orange or red.
– gumakettell
Nov 19 at 15:50
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a column that looks like this :
0 // Red colored
0 // Red colored
0 (1) // Orange colored
0 (2) // Red colored
0 // Orange colored
0 // Red colored
0 (24) // Orange colored
0 (4) // Red colored
0 // Orange colored
0 (3) // Orange colored
1
1
1 (7)
2
2 (3)
2
... etc
I would get the following order :
0 // Red colored
0 // Red colored
0 // Red colored
0 (24) // Red colored
0 (4) // Red colored
0 (2) // Red colored
0 // Orange colored
0 // Orange colored
0 (4) // Orange colored
0 (1) // Orange colored
1
1
1 (7)
2
2 (3)
2
... etc
I want to order this column in datatables using these 3 criteria : first order by number (0's), then by color (red first), then by number un parantheses (the highest first).
I've got in each data-order
the following format : 0r24
which means the first number is zero, the color is red, the number in the parantheses is 24. Repeat for all others.
I tried to play with the columnDefs
attribute of Datatables to get my result by doing the following :
"columnDefs": [
{
"type": "num-fmt",
"targets": 7
}, {
"targets": [7],
"render": function ( data, type, row, meta ) {
return type === 'sort' ?
row[7]['@data-order'].replace(/r/g,'0').replace(/o/g,'1') : row[7]['@data-order'];
}
}
]
Here I am trying to replace the letters o
and r
with 0
and 1
to be able to have an all numeric value for it to order upon, but it doesn't work. Any idea how to make this work and do the following as I explained?
javascript jquery datatables
New contributor
I have a column that looks like this :
0 // Red colored
0 // Red colored
0 (1) // Orange colored
0 (2) // Red colored
0 // Orange colored
0 // Red colored
0 (24) // Orange colored
0 (4) // Red colored
0 // Orange colored
0 (3) // Orange colored
1
1
1 (7)
2
2 (3)
2
... etc
I would get the following order :
0 // Red colored
0 // Red colored
0 // Red colored
0 (24) // Red colored
0 (4) // Red colored
0 (2) // Red colored
0 // Orange colored
0 // Orange colored
0 (4) // Orange colored
0 (1) // Orange colored
1
1
1 (7)
2
2 (3)
2
... etc
I want to order this column in datatables using these 3 criteria : first order by number (0's), then by color (red first), then by number un parantheses (the highest first).
I've got in each data-order
the following format : 0r24
which means the first number is zero, the color is red, the number in the parantheses is 24. Repeat for all others.
I tried to play with the columnDefs
attribute of Datatables to get my result by doing the following :
"columnDefs": [
{
"type": "num-fmt",
"targets": 7
}, {
"targets": [7],
"render": function ( data, type, row, meta ) {
return type === 'sort' ?
row[7]['@data-order'].replace(/r/g,'0').replace(/o/g,'1') : row[7]['@data-order'];
}
}
]
Here I am trying to replace the letters o
and r
with 0
and 1
to be able to have an all numeric value for it to order upon, but it doesn't work. Any idea how to make this work and do the following as I explained?
javascript jquery datatables
javascript jquery datatables
New contributor
New contributor
New contributor
asked Nov 19 at 12:20
gumakettell
124
124
New contributor
New contributor
Are the actual source values"Red colored"
and"Orange colored"
?
– axelduch
Nov 19 at 13:52
@axelduch yes, my comment means that the color of the zero is orange or red.
– gumakettell
Nov 19 at 15:50
add a comment |
Are the actual source values"Red colored"
and"Orange colored"
?
– axelduch
Nov 19 at 13:52
@axelduch yes, my comment means that the color of the zero is orange or red.
– gumakettell
Nov 19 at 15:50
Are the actual source values
"Red colored"
and "Orange colored"
?– axelduch
Nov 19 at 13:52
Are the actual source values
"Red colored"
and "Orange colored"
?– axelduch
Nov 19 at 13:52
@axelduch yes, my comment means that the color of the zero is orange or red.
– gumakettell
Nov 19 at 15:50
@axelduch yes, my comment means that the color of the zero is orange or red.
– gumakettell
Nov 19 at 15:50
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
gumakettell is a new contributor. Be nice, and check out our Code of Conduct.
gumakettell is a new contributor. Be nice, and check out our Code of Conduct.
gumakettell is a new contributor. Be nice, and check out our Code of Conduct.
gumakettell 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%2f53374511%2fsort-by-multiple-criteria%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
Are the actual source values
"Red colored"
and"Orange colored"
?– axelduch
Nov 19 at 13:52
@axelduch yes, my comment means that the color of the zero is orange or red.
– gumakettell
Nov 19 at 15:50