Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Augment Strava Segment Sorter with Ordinal column #7

Open
oaustegard opened this issue Aug 19, 2024 · 0 comments
Open

Augment Strava Segment Sorter with Ordinal column #7

oaustegard opened this issue Aug 19, 2024 · 0 comments

Comments

@oaustegard
Copy link
Owner

javascript:(function() {
    const sortFunctions = {
        // ... (rest of the sort functions remain the same)
    };

    function prepareTable(table) {
        // ... (rest of the prepareTable function remains the same)

        // Add ordinal order column
        const ordinalHeader = document.createElement('th');
        ordinalHeader.textContent = '#';
        ordinalHeader.style.cursor = 'pointer';
        table.querySelector('thead tr').prepend(ordinalHeader);

        const rows = table.querySelectorAll('tbody tr');
        rows.forEach((row, index) => {
            const ordinalCell = document.createElement('td');
            ordinalCell.textContent = index + 1;
            row.prepend(ordinalCell);
        });
    }

    function makeSortable(table) {
        prepareTable(table);
        const headers = table.querySelectorAll('th');
        headers.forEach((header, index) => {
            header.addEventListener('click', () => sortTable(table, index));
        });
    }

    function sortTable(table, column) {
        // ... (rest of the sortTable function remains the same)

        const sortFunction = (() => {
            switch(column) {
                case 0: return (a, b) => sortFunctions.numeric(a, b, 'td:nth-child(1)'); // Sort by ordinal order
                case 1: return sortFunctions.star; 
                // ... (rest of the case statements need to be adjusted for the new column)
            }
        })();

        // ... (rest of the sortTable function remains the same)
    }

    // ... (rest of the code remains the same)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant