Display row markers in tables not just the data grid

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

rank team score
1 red 500
2 blue 480
3. green 100

Any ideas?

I would use use case number 2 in the following post, but use a sorted query instead of a relation.

1 Like

Do you need to account for ties?

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.

and YES - I do need to account for ties.

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

Gets something like this.

1 Like

Do you mean by clicking the table column headers? I don’t believe that is possible.

That’s cheating :stuck_out_tongue:
I used 8 computed columns, haha

2 Likes

looks like this is just what i need. thanks.

foirst time embedded js in a glide app for me. is this post the one to use?

If you use my JS, it’s in the JavaScript column in the data view to calculate the rank, and not something you embed.

2 Likes