I have a table that ranks teams based on their score. I would like to display the row marker value in the table view like the data grid currently does.
example where rank is dynamically generated in the table view like the data grid
i don’t need to populate auto-incremented rows numbers in columns. I only want to display ranking when the table is sorted - just like the data grid currently does. But I want to use a table to avoid enabling data entry.
if entry 3 is now the top score it will be listed in the first row of the collection viewer.
I used JavaScript for a use case like this recently.
function getRank(clicksJoined, clicksCount) {
// Split the joined clicks string into an array of numbers
const clicksArray = clicksJoined.split(', ').map(Number);
// Sort the clicks array in descending order
clicksArray.sort((a, b) => b - a);
// Initialize rank and previous click count
let rank = 1;
let previousCount = clicksArray[0];
// Iterate through the sorted clicks array to determine the rank
for (let i = 1; i < clicksArray.length; i++) {
if (clicksArray[i] < previousCount) {
rank = i + 1;
previousCount = clicksArray[i];
}
if (clicksArray[i] === clicksCount) {
return rank;
}
}
// If the clicksCount is the highest, return 1
if (clicksCount === clicksArray[0]) {
return 1;
}
// If the clicksCount is not found in the array, return -1 (indicating not ranked)
return -1;
}
return getRank(p1, p2)
p1: Comma-delimited list of all “scores”
p2: Current row’s score