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?










share|improve this question







New contributor




gumakettell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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















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?










share|improve this question







New contributor




gumakettell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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













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?










share|improve this question







New contributor




gumakettell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question







New contributor




gumakettell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




gumakettell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




gumakettell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 19 at 12:20









gumakettell

124




124




New contributor




gumakettell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





gumakettell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






gumakettell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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










  • @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

















active

oldest

votes











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',
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
});


}
});






gumakettell is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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






























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.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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





















































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







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'