5.0.1 • Published 2 years ago

@paprika/filter v5.0.1

Weekly downloads
137
License
MIT
Repository
github
Last release
2 years ago

@paprika/filter

Description

Filter

Installation

yarn add @paprika/filter

or with npm:

npm install @paprika/filter

Props

Filter

PropTyperequireddefaultDescription
numberAppliednumberfalse0
childrennodefalsenull
columnsarrayOftrue-
dataarrayOffalsenull
maxFiltersAllowednumberfalse9999
onAddFilterfunctrue-
onApplyfunctrue-
onCancelfuncfalse() => {}
onChangeOperatorfuncfalsenull
onClearfuncfalse() => {}
operator Filter.operator.AND, Filter.operator.ORfalseFilter.operator.AND
rulesByTypeobjectOffalseFilter.defaultRulesByType
zIndexnumberfalseundefined

Item

PropTyperequireddefaultDescription
columnIdstringtrue-
idstring,numberfalsenull
indexnumbertrue-
onChangeFilterfunctrue-
onDeleteFilterfunctrue-
renderValueFieldfuncfalsenull
rulestringtrue-
valuestring,bool,array,numbertrue-

Filter

Usage (no hooks)

import Filter from "@paprika/filter";

<Filter
  columns={columnsSettings}
  data={data}
  numberApplied={1}
  onAddFilter={() => {}}
  onApply={() => {}}
  onCancel={() => {}}
  onChangeOperator={() => {}}
  onClear={() => {}}
>
  <Filter.Item
    columnId="name"
    id={1234}
    index={0}
    type="TEXT"
    rule="CONTAINS"
    value="abc"
    onChangeFilter={() => {}}
    onRemoveFilter={() => {}}
  />
</Filter>;

More detail about props

Usage (with hooks)

Please note that the built-in filter functions only work with flat data arrary. Please pass in a flattened array if you want to use the built-in feature. If you want to use your own filter algorithm you can still use the hook, just do not pass in the data property and ignore the filteredData in the returned value.

const { filteredData, filters, getFilterProps, getFilterItemProps } = useFilter({ columns, rulesByType, data });

const handleDeleteFilter = filterId => () => {
  onDeleteFilter(filterId);
};
const handleChangeFilter = filterId => params => {
  onChangeFilter({ ...params, id: filterId });
};

return (
  <Filter {...getFilterProps()} columns={columnsSettings} data={data}>
    {filters.map((filter, index) => (
      <Filter.Item
        {...getFilterItemProps()}
        columnId={filter.columnId}
        id={filter.id}
        index={index}
        key={filter.id}
        type={filter.type}
        rule={filter.rule}
        value={filter.value}
      />
    ))}
  </Filter>

  // display filteredData
);

Variations

  • You can prevent the user from having to choose between AND and OR by setting the onChangeOperator prop to null and including the operator to use.

Links

5.0.1

2 years ago

5.0.1-next.0

2 years ago

5.0.0

2 years ago

5.0.0-next.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.0-next.0

2 years ago

4.0.1-next.0

2 years ago

3.0.4-next.0

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.3-next.0

3 years ago

3.0.2-next.0

3 years ago

3.0.0-next.1

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

3.0.1-next.0

3 years ago

3.0.1-next.1

3 years ago

2.1.4-next.1

3 years ago

2.1.7-next.0

3 years ago

2.1.4-next.2

3 years ago

2.1.3-next.0

3 years ago

2.1.3-next.1

3 years ago

2.1.4-next.0

3 years ago

2.1.5-next.0

3 years ago

2.1.6-next.0

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.7

3 years ago

2.1.2-next.1

3 years ago

2.1.2-next.0

3 years ago

2.1.2

3 years ago

2.0.6

4 years ago

2.1.0-next.2

4 years ago

2.1.0-next.1

4 years ago

2.1.0-next.0

4 years ago

2.1.1-next.0

3 years ago

2.1.1-next.1

3 years ago

2.1.1

3 years ago

2.1.0

4 years ago

2.0.6-next.0

4 years ago

2.0.3

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.5-next.0

4 years ago

2.0.5-next.1

4 years ago

2.0.3-next.1

4 years ago

2.0.3-next.0

4 years ago

2.0.4-next.2

4 years ago

2.0.4-next.0

4 years ago

2.0.4-next.1

4 years ago

2.0.2

4 years ago

2.0.2-next.0

4 years ago

2.0.1

4 years ago

2.0.2-next.1

4 years ago

2.0.1-next.1

4 years ago

2.0.1-next.0

4 years ago

2.0.0

4 years ago

2.0.0-next.1

4 years ago

1.2.16-next.0

4 years ago

1.2.14-next.0

4 years ago

1.2.15-next.0

4 years ago

1.2.14

4 years ago

1.2.15

4 years ago

1.2.13

4 years ago

1.2.13-next.0

4 years ago

1.2.12

4 years ago

1.2.12-next.0

4 years ago

1.2.11

4 years ago

1.2.11-next.0

4 years ago

1.2.10

4 years ago

1.2.10-next.0

4 years ago

1.2.9-next.0

4 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.8-next.0

4 years ago

1.2.7

4 years ago

1.2.7-next.0

4 years ago

1.2.6

4 years ago

1.2.6-next.0

4 years ago

1.2.5

4 years ago

1.2.5-next.0

4 years ago

1.2.4

4 years ago

1.2.4-next.1

4 years ago

1.2.4-next.0

4 years ago

1.2.3

4 years ago

1.2.3-next.0

4 years ago

1.2.2

4 years ago

1.2.2-next.0

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.2.1-next.2

4 years ago

1.2.1-next.0

4 years ago

1.2.1-next.1

4 years ago

1.2.0-next.2

4 years ago

1.2.0-next.1

4 years ago

1.2.0-next.0

4 years ago

1.1.12-next.1

4 years ago

1.1.11-next.0

4 years ago

1.1.12

4 years ago

1.1.12-next.0

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.10-next.0

4 years ago

1.1.10-next.1

4 years ago

1.1.9

4 years ago

1.1.9-next.0

4 years ago

1.1.8

4 years ago

1.1.8-next.0

4 years ago

1.1.7

4 years ago

1.1.7-next.0

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.6-next.0

4 years ago

1.1.5-next.0

4 years ago

1.1.4

4 years ago

1.1.4-alpha.7

4 years ago

1.1.4-alpha.6

4 years ago

1.1.4-alpha.5

4 years ago

1.1.4-alpha.4

4 years ago

1.1.4-alpha.3

4 years ago

1.1.4-alpha.2

4 years ago

1.1.4-alpha.0

4 years ago

1.1.4-alpha.1

4 years ago

1.1.3

4 years ago

1.1.3-alpha.1

4 years ago

1.1.3-alpha.0

4 years ago

1.1.2

4 years ago

1.1.2-alpha.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.1-alpha.0

4 years ago

1.0.2-alpha.0

4 years ago

1.0.1

4 years ago

1.0.1-alpha.0

4 years ago

1.0.0

4 years ago

0.1.1-alpha.1

4 years ago

0.1.1-alpha.0

4 years ago