Skip to content

Commit

Permalink
fix: handle value undefined in table sort
Browse files Browse the repository at this point in the history
  • Loading branch information
harshpatel-crest committed Jul 12, 2021
1 parent da76a93 commit 05b854a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ui/src/main/webapp/components/table/TableWrapper.jsx
Expand Up @@ -209,10 +209,14 @@ function TableWrapper({ page, serviceName, handleRequestModalOpen, handleOpenPag
// Sort the array based on the sort value
const sortedArr = arr.sort((rowA, rowB) => {
if (sortDir === 'asc') {
return rowA[sortKey] > rowB[sortKey] ? 1 : -1;
const rowAValue = rowA[sortKey] === undefined ? '' : rowA[sortKey];
const rowBValue = rowB[sortKey] === undefined ? '' : rowB[sortKey];
return rowAValue > rowBValue ? 1 : -1;
}
if (sortDir === 'desc') {
return rowB[sortKey] > rowA[sortKey] ? 1 : -1;
const rowAValue = rowA[sortKey] === undefined ? '' : rowA[sortKey];
const rowBValue = rowB[sortKey] === undefined ? '' : rowB[sortKey];
return rowBValue > rowAValue ? 1 : -1;
}
return 0;
});
Expand Down

0 comments on commit 05b854a

Please sign in to comment.