I'm new to React and am using the Table component from react-bootstrap.
I want to sort my table in ascending order of the 'Days Till Expiry' column.
But the Table component doesn't have a sorting property, does anyone know how I could do this?
Sorting the React table data. Now, whenever we click any of the table headers, we can sort that particular column in ascending or descending order. To achieve this, we must use an ordering function that knows how to collate and order items. In this case, we will use the sort() function.
The sort table needed a bootstrap table with a JavaScript method. There is two ways to sort table data which is below. The first way helps to sort table data automatically using the DataTable() method. The second way helps the user to sort table data as per requirement.
The sort() method will sort elements based on the return value of the compare() function with the following rules: If compare(a,b) is less than zero, the sort() method sorts a to a lower index than b . If compare(a,b) is greater than zero, the sort() method sort b to a lower index than a , i.e., b will come first.
I would recommend using react-bootstrap-table then use these examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With