Skip to content

Commit

Permalink
add orderByField to OrderByCollection (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkl4261 authored Dec 22, 2023
1 parent 458b065 commit 5b6a3a2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
7 changes: 4 additions & 3 deletions __tests__/disableSort.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ describe('Disabled Client Sorting', () => {
{
orderBy: 0,
orderDirection: 'asc',
sortOrder: 0
sortOrder: 0,
orderByField: 'number'
}
];
});
Expand All @@ -62,7 +63,7 @@ describe('Disabled Client Sorting', () => {
fireEvent.click(numberColumn);

expect(onOrderCollectionChangeSpy).toHaveBeenCalledWith([
{ sortOrder: 1, orderBy: 0, orderDirection: 'asc' }
{ sortOrder: 1, orderBy: 0, orderDirection: 'asc', orderByField: 'number' }
]);

const cells = queryAllByTestId('mtablebodyrow').map((row) =>
Expand Down Expand Up @@ -93,7 +94,7 @@ describe('Disabled Client Sorting', () => {
fireEvent.click(numberColumn);

expect(onOrderCollectionChangeSpy).toHaveBeenCalledWith([
{ sortOrder: 1, orderBy: 0, orderDirection: 'asc' }
{ sortOrder: 1, orderBy: 0, orderDirection: 'asc', orderByField: 'number' }
]);

const cells = queryAllByTestId('mtablebodyrow').map((row) =>
Expand Down
28 changes: 15 additions & 13 deletions __tests__/multiColumnSort.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ describe('Multi Column Sort', () => {
{
orderBy: 1,
orderDirection: 'asc',
sortOrder: 1
sortOrder: 1,
orderByField: 'title'
},
{
orderBy: 2,
orderDirection: 'desc',
sortOrder: 2
sortOrder: 2,
orderByField: 'name'
}
];
});
Expand All @@ -102,15 +104,15 @@ describe('Multi Column Sort', () => {
fireEvent.click(numberColumn);

expect(onOrderCollectionChangeSpy).toHaveBeenCalledWith([
{ sortOrder: 1, orderBy: 0, orderDirection: 'asc' }
{ sortOrder: 1, orderBy: 0, orderDirection: 'asc', orderByField: 'number' }
]);

const titleColumn = queryAllByTestId('mtableheader-sortlabel')[1];
fireEvent.click(titleColumn);

expect(onOrderCollectionChangeSpy).toHaveBeenCalledWith([
{ sortOrder: 1, orderBy: 0, orderDirection: 'asc' },
{ sortOrder: 2, orderBy: 1, orderDirection: 'asc' }
{ sortOrder: 1, orderBy: 0, orderDirection: 'asc', orderByField: 'number' },
{ sortOrder: 2, orderBy: 1, orderDirection: 'asc', orderByField: 'title' }
]);
});

Expand All @@ -131,17 +133,17 @@ describe('Multi Column Sort', () => {
fireEvent.click(numberColumn);

expect(onOrderCollectionChangeSpy).toHaveBeenCalledWith([
{ sortOrder: 1, orderBy: 0, orderDirection: 'asc' }
{ sortOrder: 1, orderBy: 0, orderDirection: 'asc', orderByField: 'number' }
]);

fireEvent.click(queryAllByTestId('mtableheader-sortlabel')[1]);
fireEvent.click(queryAllByTestId('mtableheader-sortlabel')[2]);
fireEvent.click(queryAllByTestId('mtableheader-sortlabel')[3]);

expect(onOrderCollectionChangeSpy).toHaveBeenCalledWith([
{ sortOrder: 1, orderBy: 1, orderDirection: 'asc' },
{ sortOrder: 2, orderBy: 2, orderDirection: 'asc' },
{ sortOrder: 3, orderBy: 3, orderDirection: 'asc' }
{ sortOrder: 1, orderBy: 1, orderDirection: 'asc', orderByField: 'title' },
{ sortOrder: 2, orderBy: 2, orderDirection: 'asc', orderByField: 'name' },
{ sortOrder: 3, orderBy: 3, orderDirection: 'asc', orderByField: 'lastName' }
]);
});

Expand All @@ -163,7 +165,7 @@ describe('Multi Column Sort', () => {
fireEvent.click(numberColumn);

expect(onOrderCollectionChangeSpy).toHaveBeenCalledWith([
{ sortOrder: 1, orderBy: 0, orderDirection: 'desc' }
{ sortOrder: 1, orderBy: 0, orderDirection: 'desc', orderByField: 'number' }
]);
});

Expand All @@ -185,9 +187,9 @@ describe('Multi Column Sort', () => {
fireEvent.click(numberColumn);

expect(onOrderCollectionChangeSpy).toHaveBeenCalledWith([
{ sortOrder: 1, orderBy: 1, orderDirection: 'asc' },
{ sortOrder: 2, orderBy: 2, orderDirection: 'desc' },
{ sortOrder: 3, orderBy: 0, orderDirection: 'asc' }
{ sortOrder: 1, orderBy: 1, orderDirection: 'asc', orderByField: 'title' },
{ sortOrder: 2, orderBy: 2, orderDirection: 'desc', orderByField: 'name' },
{ sortOrder: 3, orderBy: 0, orderDirection: 'asc', orderByField: 'number' }
]);
});
});
3 changes: 2 additions & 1 deletion src/utils/data-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ export default class DataManager {
return {
orderBy: columnDef.tableData.id,
sortOrder: undefined,
orderDirection: ''
orderDirection: '',
orderByField: columnDef.field
};
}
});
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface OrderByCollection {
orderBy: number;
orderDirection: string;
sortOrder: number;
orderByField: string;
}

export interface MaterialTableProps<RowData extends object> {
Expand Down

0 comments on commit 5b6a3a2

Please sign in to comment.