Hey Gliders. Can you help me Sort a relation?
I need this because I want to fire a webhook with some data. But it needs to sort the relational data.
Any thoughts
In the sheets
A has 3
B has 1
C has 2
I want to the webhook to sent
B,C,A
Hey Gliders. Can you help me Sort a relation?
I need this because I want to fire a webhook with some data. But it needs to sort the relational data.
Any thoughts
In the sheets
A has 3
B has 1
C has 2
I want to the webhook to sent
B,C,A
So to paraphrase, you want to create a joined list of column values via a relation, but have the list sorted by the values in a separate column, yes?
I don’t think this is possible using just native Glide computed columns.
But I have an Experimental Code column that will get you very close, and would be easy enough to modify to get what you want.
The modification you would need to make would be in Line 27 of function.js, just including a comma as a delimiter in the return value, ie:
var joined = sorted.join(',');
With that modification, you could use it as follows:
Hola
This is another easy solution by using the @Darren_Murphy’s idea: using the JavaScript plugin.
Taking advantage of this plugin supports 3 parameters (I hope someday it can handle at least 5 and can return an array’s values ), we can have this simple code:
const Values= [p1, p2, p3];
Values.sort();
return Values[0] + "," + Values[1] + "," + Values[2] ;
Of course, you must have 3 columns in the same sheet to get it (3 Simple Value columns can help you)!!
Saludos!
I’m not sure that this actually gives the desired result, although I may have misunderstood what was being asked. Wouldn’t be the first time
Well, you are not alone!!
I’m thinking frequently that my english is causing me problems to understand some questions (or people don’t want to say all truth at the beginning).
Not related to this thread, but I wanted to respond to this. While there are only three parameters available in the javascript plugin, you can still pass many more. In the image below, I passed in a P1, P2, and P3 parameter, but each parameter was filled with multiple other pieces of information using a comma delimiter in between. I was then able to split them into 12 variables to use throughout the rest of the code.
Kind of the same thing if you wanted an array out of the javascript. Just return a string of delimited text and use a Split Text column to turn it into an array.
you need two columns:
Create another one:
var FirtstSortColumn = p1.split(",");
var SecondColumn = p2.split(",");
var arr = [];
for (var i = 0; i < p2.split(",").length; i++) {
arr.push([FirtstSortColumn[i],SecondColumn[i]]);
}
arrsorted=arr.sort(sortFunction);
function sortFunction(a, b) {
if (a[0] === b[0]) {
return 0;
}
else {
return (a[0] < b[0]) ? -1 : 1;
}
}
var arrfinal = [];
for (var i = 0; i < p2.split(",").length; i++) {
arrfinal.push([arrsorted[i][1]]);
}
return arrfinal.toString();
p1: Joined List 2
p2: Joined List 1
p3: leave empty