Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 38 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ import { reducer, epics } from '@flipbyte/redux-datatable';
width: 150,
filterable: true,
sortable: true,
}, {
label: "Status",
type: "options",
name: "entityData.data.status",
sortable: true,
filterable: true,
textAlign: "center",
options: {
"published": {
label: "Published"
},
"draft": {
label: "Draft"
},
"archived": {
label: "Archived"
}
}
}, {
label: 'Avatar',
type: 'image',
Expand Down Expand Up @@ -249,22 +267,24 @@ toolbar items. Each inner array represents a different row.

#### Columns object

| Key | Type | Required | Default | Description |
| ------------------------------- | ------------ | -------- | ------- | ------------------------------------------------------------------------- |
| name | string | true | - | Unique name for the column |
| label | string | true | - | Label for the column |
| sortable | boolean | false | true | Whether the column is sortable |
| filterable | boolean | false | true | Whether the column is filterable |
| type | string | true | string | Available types: selection, number, date, string, image, actions |
| width | integer | true | - | Width of the column |
| extraData | string/array | false | - | properties from the state to pass as in the extra object |
| textAlign | string | false | left | Text alignment in the column |
| **type: actions** | | | | |
| items | array | true | - | array of item configuration object |
| **- item configuration object** | | | | |
| name | string | true | - | Unique name for the action |
| label | string | true | - | Label for the action |
| thunk | function | true | - | An action creator which is dispatched on action click. Check demo schema. |
| Key | Type | Required | Default | Description |
| ------------------------------- | ------------ | -------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name | string | true | - | Unique name for the column |
| label | string | true | - | Label for the column |
| sortable | boolean | false | true | Whether the column is sortable |
| filterable | boolean | false | true | Whether the column is filterable |
| type | string | true | string | Available types: selection, number, date, string, image, options, actions |
| width | integer | true | - | Width of the column |
| extraData | string/array | false | - | properties from the state to pass as value in the extra object. |
| textAlign | string | false | left | Text alignment in the column |
| **type: options** | | | | |
| options | object | true | - | object of objects with key for each child object being the value of the column and child object being { label: "{Your label for the respective value}" } |
| **type: actions** | | | | |
| items | array | true | - | array of item configuration object |
| **- item configuration object** | | | | |
| name | string | true | - | Unique name for the action |
| label | string | true | - | Label for the action |
| thunk | function | true | - | An action creator which is dispatched on action click. Check demo schema. |

#### Styles object

Expand All @@ -289,7 +309,9 @@ Styles has the following properties available:
The MIT License (MIT)

[npm-badge]: https://img.shields.io/npm/v/@flipbyte/redux-datatable.svg

[npm]: https://www.npmjs.com/package/@flipbyte/redux-datatable

[codacy-badge]: https://api.codacy.com/project/badge/Grade/67274650b4874f5db55ede76156ab4d2

[codacy]: https://www.codacy.com/app/flipbyte/redux-datatable?utm_source=github.com&utm_medium=referral&utm_content=flipbyte/redux-datatable&utm_campaign=Badge_Grade
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flipbyte/redux-datatable",
"version": "0.2.2",
"version": "0.3.0",
"description": "React-Redux data table",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
2 changes: 2 additions & 0 deletions src/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MassActions from './Renderer/Toolbar/MassActions';
import ResetFilters from './Renderer/Toolbar/ResetFilters';

import DateFilter from './Renderer/Filter/Date';
import FilterOptions from './Renderer/Filter/Options';
import String from './Renderer/Filter/String';
import Number from './Renderer/Filter/Number';

Expand All @@ -33,6 +34,7 @@ const renderers = {
filter: {
number: Number,
date: DateFilter,
options: FilterOptions,
default: String
},
body: {
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/Body/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Options = ({

return (
<span className={ (options[value].badge ? 'badge ' + options[value].badge : '') }>
{ options[value].value }
{ options[value].label }
</span>
);
};
Expand Down
33 changes: 33 additions & 0 deletions src/Renderer/Filter/Options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import _ from 'lodash';
import React from 'react';
import { OPERATOR } from '../../constants';
import Field from '../../components/Field';

const applyFilter = ( filterer, event ) => {
let filter = {};
if (event.target.value) {
filter = {
operator: OPERATOR.IS,
field: event.target.name,
value: event.target.value,
logic: 'where',
};
}

filterer(event.target.name, filter);
};

const Options = ({ name, value = '', filterer, options }) => (
<Field.Select
name={ name }
value={ value }
onChange={ applyFilter.bind(this, filterer) }
>
<option></option>
{ _.map(options, ({ label }, key ) => (
<option key={ key } value={ key }>{ label }</option>
) )}
</Field.Select>
);

export default Options;