Skip to content

Commit

Permalink
Fix reportedSortName coming back as name instead of field
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Feb 1, 2022
1 parent c8938fa commit d155260
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/components/basic_table/in_memory_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,21 @@ export class EuiInMemoryTable<T> extends Component<
// from sortName; sortName gets stored internally while reportedSortName is sent to the callback
let reportedSortName = sortName;

// EuiBasicTable returns the column's `field` if it exists instead of `name`,
// map back to `name` if this is the case
for (let i = 0; i < this.props.columns.length; i++) {
const column = this.props.columns[i];
if (
'field' in column &&
(column as EuiTableFieldDataColumnType<T>).field === sortName
) {
sortName = column.name as keyof T;
break;
// EuiBasicTable returns the column's `field` instead of `name` on sort
// and the column's `name` instead of `field` on pagination
if (sortName) {
const { columns } = this.props;
let sortColumn = findColumnByProp(columns, 'field', sortName as string);
if (sortColumn == null) {
sortColumn = findColumnByProp(columns, 'name', sortName as string);
}
if (sortColumn) {
// Ensure sortName uses `name`
sortName = sortColumn.name as keyof T;

// Ensure reportedSortName uses `field` if it exists
const sortField = (sortColumn as EuiTableFieldDataColumnType<T>).field;
if (sortField) reportedSortName = sortField as keyof T;
}
}

Expand Down

0 comments on commit d155260

Please sign in to comment.