I have implemented the below-sorting functionality to sort the column with numeric values, and it is working fine. I am looking way to extract a separate function so that I don't have to repeat the data index twice for each column in the column configuration array
const supplyAirHandlersTableColumns = [
{
title: <StrongTitleWithUnit title="Min Airflow"/>,
dataIndex: ['supplyAirflow', 'minAirflow'],
sorter: (a, b) => SORTABLE.NUMERIC(a, b, ['supplyAirflow', 'minAirflow']),
render: Math.round
},
{
title: <StrongTitleWithUnit title="Max Airflow"/>,
dataIndex: ['supplyAirflow', 'maxAirflow'],
sorter: (a, b) => SORTABLE.NUMERIC(a, b, ['supplyAirflow', 'maxAirflow']),
render: Math.round
}
]
And below is the function for SORTABLE.NUMERIC
export const SORTABLE = Object.freeze({
NUMERIC: compareNumericProps
});
export const compareNumericProps = (a, b, prop) => get(a, prop) - get(b, prop);
Could anyone please let me know if I can extract this as a function to avoid repetitive data index, and I am using Antd UI library with react js?
Many thanks in advance!!!
I am looking like this kind of function sorter: sortNumericValue.