|
Ultima modificación |
Ver Log
|
| Rev |
Autor |
Línea Nro. |
Línea |
| 15312 |
stevensc |
1 |
export const sortTableData = ({ tableData, sortKey, reverse }) => {
|
|
|
2 |
let sortedData
|
|
|
3 |
|
|
|
4 |
if (!sortKey) return tableData
|
|
|
5 |
|
|
|
6 |
sortedData = tableData.sort((a, b) => {
|
|
|
7 |
if (typeof a[sortKey] === 'string') {
|
|
|
8 |
return a[sortKey].toLowerCase() < b[sortKey].toLowerCase() && -1
|
|
|
9 |
}
|
|
|
10 |
return a[sortKey] - b[sortKey]
|
|
|
11 |
})
|
|
|
12 |
|
|
|
13 |
if (reverse) return sortedData.reverse()
|
|
|
14 |
|
|
|
15 |
return sortedData
|
|
|
16 |
}
|