| 1642 | * Sorts the given data based on the selected sort option | 1642 | * Sorts the given data based on the selected sort option |
| 1643 | * | 1643 | * |
| 1644 | * @param {any[]} data WI entries | 1644 | * @param {any[]} data WI entries |
| | 1645 | * @param {object} [options={}] - Optional arguments |
| | 1646 | * @param {{sortField?: string, sortOrder?: string, sortRule?: string}} [options.customSort={}] - Custom sort options, instead of the chosen UI sort |
| 1645 | * @returns {any[]} Sorted data | 1647 | * @returns {any[]} Sorted data |
| 1646 | */ | 1648 | */ |
| 1647 | export function sortWorldInfoEntries(data) { | 1649 | export function sortWorldInfoEntries(data, { customSort = null } = {}) { |
| 1648 | const option = $('#world_info_sort_order').find(':selected'); | 1650 | const option = $('#world_info_sort_order').find(':selected'); |
| 1649 | const sortField = option.data('field'); | 1651 | const sortField = customSort.sortField ?? option.data('field'); |
| 1650 | const sortOrder = option.data('order'); | 1652 | const sortOrder = customSort.sortOrder ?? option.data('order'); |
| 1651 | const sortRule = option.data('rule'); | 1653 | const sortRule = customSort.sortRule ?? option.data('rule'); |
| 1652 | const orderSign = sortOrder === 'asc' ? 1 : -1; | 1654 | const orderSign = sortOrder === 'asc' ? 1 : -1; |
| 1653 | | 1655 | |
| 1654 | if (!data.length) return data; | 1656 | if (!data.length) return data; |