Sorting
Description
sorting data is possible by passing the attribute sorting
in the initialDataState
object and sortable
option
Usage example
Code
import CustomDataTable from "@components/custom-data-table/CustomDataTable";
function Demo() {
const data = [
{
name: "Bob",
lastActive: "2018-07-18T10:09:30.662Z",
score: 10.5,
},
{
name: "Jane",
lastActive: "2018-07-13T10:09:30.662Z",
score: 12,
},
{
name: "Fred",
lastActive: "2018-07-19T10:09:00.662Z",
score: 9.5,
},
];
const columns = [
{ accessorKey: "name", header: "Name" },
{
accessorKey: "lastActive",
header: "Last Active",
meta: { dataType: "date" },
},
{ accessorKey: "score", header: "Score", meta: { dataType: "decimal" } },
];
const options = {
data: data,
columns: columns,
sortable: true,
initialDataState: {
sorting: [
{
id: "score",
desc: true,
},
],
},
};
return <CustomDataTable options={options}></CustomDataTable>;
}
Result
Jane | 13/07/2018 | 12 |
Bob | 18/07/2018 | 10.5 |
Fred | 19/07/2018 | 9.5 |