🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

mantine-datatable-filter

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mantine-datatable-filter

Column filter, sorting and pagination handler for mantine-datatable

1.0.9
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Mantine Datatable Filter

a lightweight hook which help to handle mantine datatable filtering, column sorting and pagination.

Installation

npm install mantine-datatable-filter

Dependencies

  • @mantine/core
  • @mantine/hooks
  • mantine-datatable

Example

  • Import libraries.
import { DataTable } from 'mantine-datatable'
import useMantineDataTableFilter from 'mantine-datatable-filter'
  • Create handler hook.
const dtFilter = useMantineDataTableFilter({
    sort: {
        columnAccessor: 'id',
        direction: 'desc',
    },
    pagination: {
        totalRecords: totalRecords ?? 0,
        sizes: [10, 15, 20],
    },
    columns: [
      {
          accessor: 'id',
          type: 'number',
          inputProps: {
              label: 'ID',
              placeholder: 'Search by ID',
          }
      },
      {
          accessor: 'name',
          type: 'text',
          inputProps: {
              label: 'Name',
              placeholder: 'Search by name',
          }
      }
    ],
    onChange: (values, cleanedValues) => {
        // handle change
    },
    debounced: 200
})
  • Add props to datatable.
return <DataTable
           // Add handler props here.
           {...dtFilter.props}
           columns={[
               {
                 accessor: 'id',
                 title: 'ID',
                 sortable: true,
                 // Add filter props for each of columns.
                 ...dtFilter.getFilterProps('id')
               },
               {
                 accessor: 'name',
                 title: 'Name',
                 sortable: true,
                 ...dtFilter.getFilterProps('name')
               }
           ]}
       />

APIs

HandlerOptions

columns

PropertyTypeDefault ValueDescription
accessorstringPrimary key for each column.
type"text" | "number" | "date" | "datetime" | "select"Column type.
post?(value: "text" | "number" | "date" | "datetime" | "select") => "text" | "number" | "date" | "datetime" | "select"() => {}Post process function for a column. Note this will affect only for cleaned value.
inputProps?InputProps{}Props for filter input. Please refer to mantine documentations for input props.
resetLabel?string"Reset"Date type only.

sorts?

PropertyTypeDefault ValueDescription
columnAccessorstringDefault sorting key.
direction"asc" | "desc"Direction of sorting.

pagination

PropertyTypeDefault ValueDescription
initialPagenumber1Initial page.
totalRecordsnumberTotal records.
sizes?number | number[]10Total records per page.

onChange(values, cleanedValues) => void

PropertyTypeDefault ValueDescription
valuesHandlerValuesRaw values.
cleanedValuesHandlerCleanedValuesCleaned, with post data process and removed blank filters' values.
PropertyTypeDefault ValueDescription
debounced?number0Debounced state for onChange when user input on filters.
deps?DependencyList | any[][]Dependencies for triggering onChange. This is useful for adding extra features to the handler.

HandlerReturn

PropertyTypeDescription
valuesHandlerValuesHandler values.
getFilterProps(accessor: string) => FilterPropsGetter for generating filter option props for a column.
refetch() => voidFunction for triggering onChange.
propsDatatablePropsSorting and pagination props for datatable.

HandlerValues

PropertyTypeDescription
sortDataTableSortStatus | nullColumn for sorting.
filtersall of { key: FilterType }Column filters values.
pagination{ page: number; size: number }Column pagination values.

FilterType

PropertyTypeDescription
accessorstringPrimary key for each column.
type"text" | "number" | "date" | "datetime" | "select"Column type.
value(depends on type, refer to mantine documentation)Column value.

FAQs

Package last updated on 02 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts