Skip to main content

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

Jane13/07/201812
Bob18/07/201810.5
Fred19/07/20189.5