1.0.8 • Published 6 years ago

@adler-it/webstack-datagrid v1.0.8

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

Classes

SortConfig

Construtor

(id: string)

FilterConfig

Construtor

(id: string)

Method

NameArgumentsReturn TypeDescription
numberFilterConfigMake it Number filter.
dateFilterConfigMake it Date filter.
stringFilterConfigMake it String filter.
select(options: T[], value: (option: T) => string | number, label: (option: T) => string | number, multi: boolean)FilterConfigMake it select filter.
autoComplete(options: T[], pathToValue: string, pathToText: string)FilterConfigMake it autocomplete filter.
autoCompleteSimple(options: string[])FilterConfigMake it autocomplete filter.

DataGridConfig

Constructor

(selectable: boolean = false, multiSelectable: boolean = false, striped: boolean = false, hover: boolean = false)

Method

NameArgumentsReturn TypeDescription
addColumn(label: string, style: object, value: (row: object) => string, sortConfig: SortConfig = false, filterConfig: FilterConfig = false)DataGridConfigAdd column to dataGridConfig.
addSpace(width: string)DataGridConfigAdd blank column of given width.
addButtonAction(onClick: (index: number, row: T) => void, element: JSX)DataGridConfigAdd ActionButton to row.
addTranslation(filter: string, sort: string, operation: string, value: string, values: string, ok: string, clear: string, close: string)DataGridConfigAdd translation.

Components

DataGrid

Properties

NameTypeDefaultDescription
rows*T[]Data to display.
config*DataGridConfigDataGrid Config.
actionPlacementstring"left"Placement of action buttons in rows.
paging{ page: number, pageSize: number, count: number}Pagination to display.
onUpdate*(paging, sort, filter) => voidUpdate Callback.
fetchingbooleanfalseLoading indication.
pageSizesnumber[]15,30,50,100PageSize for Pagination.

Usage

import DataGrid, { DataGridConfig, FilterConfig, SortConfig } from '@adler-it/webstack-datagrid';
import { IconButton } from 'material-ui';
import Remove from 'material-ui/svg-icons/action/highlight-off';
import moment from 'moment';

const genders = [
	{
		id: 1,
		name: "female"
	},
	{
		id: 2,
		name: "male"
	}
]

const data = [
	{
		_id: "7"
		firstName: "John",
		lastName: "Doe",
		birthday: "1993-06-16T00:00:00.000Z",
		gender: 1,
		mother: 5,
	},
	{
		_id: "5"
		firstName: "Jane",
		lastName: "Doe",
		birthday: "1970-06-16T00:00:00.000Z",
		gender: 2,
		mother: null,
	},...
]

const lastNames = data.map(person => person.lastName);
const config = new DataGridConfig(false, false, true, true)
	.addTranslation('Filter', 'Sort', 'Operation', 'Value', 'Values', 'OK', 'Clear', 'Close')
	.addColumn('ID', { width: '0px' }, row => row.id, new SortConfig('_id'), new FilterConfig('_id').number())
	.addColumn('First Name', { width: '90px' }, row => row.firstName, new SortConfig('firstName'), new FilterConfig('firstName').string())
	.addColumn('First Name', { width: '90px' }, row => row.firstName, new SortConfig('firstName'), new FilterConfig('firstName').autoCompleteSimple(lastNames))
	.addColumn('Birthday', { width: '50px' }, row => moment(row.birthday).format('DD.MM.YYYY'), false, new FilterConfig('birthday').date())
	.addColumn('Gender', {width: '0px'}, row => genders.find(item => item.id === row.gender), false, new FilterConfig('gender').select(genders, item => item.id, item => item.name, false))
	.addColumn('Mother', {width: '150px'}, row => data.find(item => item._id === row.mother), false, new FilterConfig('mother').autoComplete(data, item => item._id, item => `${item.firstName} ${item.lastName}`))
	.addButtonAction((index, item) => console.log('You clicked on row number ${index}, item with id ${item._id}', <IconButton><Remove /></IconButton>))
...
render() {
	return (
		<div>
			<DataGrid
				rows={data}
				config={config}
				onUpdate={(newState) => console.log(newState)}
			>
		</div>
	)
}
1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago