export function sortByName()

in source/console/src/util/CustomUtil.tsx [225:239]


export function sortByName(data: any[], sortBy: SortBy, sortKey: string, keyType?: string): any[] {
  if (sortBy === SortBy.Asc) {
    if (keyType === 'number') {
      return data.sort((a, b) => (a[sortKey] ? a[sortKey] : 0) - (b[sortKey] ? b[sortKey] : 0));
    } else {
      return data.sort((a, b) => (a[sortKey] ? a[sortKey] : '').localeCompare(b[sortKey] ? b[sortKey] : ''));
    }
  } else {
    if (keyType === 'number') {
      return data.sort((a, b) => (b[sortKey] ? b[sortKey] : 0) - (a[sortKey] ? a[sortKey] : 0));
    } else {
      return data.sort((a, b) => (b[sortKey] ? b[sortKey] : '').localeCompare(a[sortKey] ? a[sortKey] : ''));
    }
  }
}