4.0.0-beta-0.17 • Published 5 months ago

@syook/react-tabulous v4.0.0-beta-0.17

Weekly downloads
94
License
-
Repository
github
Last release
5 months ago

React-Tabulous 🎉

Installation

To use in your own project, install it via npm package.

npm i @syook/react-tabulous

Or you can clone.

git clone git@github.com:syook/react-tabulous.git

Options

a. Available Column Options

OptionDescriptionTypeisRequiredDefault
headerNameName of Column to be shown in headerStringtrue
typetype of the fieldStringtrue
fieldpath to get value to be displayedStringtrue
valueGettershould return string that to be displayed in the cell or used in filterFunctionfalsenull
renderCellreturns the element to be shown in the column cellFunctionfalsenull
descriptionshows the description of the column on hover in tooltipStringfalse''
isSortableis column sortableBooleanfalsefalse
isSearchableis column searchableBooleanfalsefalse
isFilterableis column filterableBooleanfalsefalse
isVisibleshould hide/show the column or notBooleanfalsetrue
optionsarray of options if the type is MultiSelect or Single SelectArrayfalse[]
isResizableis column resizableBooleanfalsefalse
pinnedString='left' or 'right', where to fix the columnStringfalsenull
widthto fix column width to a value in pixels if width exceeding this thresholdNumberfalsenull

c. Available Types

TypeFilter queries availableExtra props needed
stringcontains, does not contains, is, is not, is empty, is not empty
dateTime/dateis, is not, is after, is before, is empty, is not empty
number=, =/ , < , <=, > , >= , is empty, is not empty
singleSelecthas any of, has none of, is empty, is not emptyoptions: []
multiSelectis, is not, is empty, is not empty,options: []

d. Component Props

PropDescriptionDefaultRequiredType
datadata for the tabletrue
columnscolumns for the table
emptyPlaceholderplaceholder for empty cells''falseString
checkboxSelectionshows checkbox for bulk actionsfalsefalseBoolean
bulkActionsbulk actions to show when checkbox selected[]falseString[]
onBulkActionClickonClick of bulk actionnullfalseFunction
loadingloading state inside the tablefalsefalseBoolean
defaultPageSizerows per page in the table10falseNumber
noRowsOverlayshows when there is no data to displayReactNodefalseString or ReactNode
densitydensity of the rowsstandardfalsestring
hidePaginationhides paginationfalsefalseBoolean
hideFooterRowCounthides row count in footerfalsefalseBoolean
hideFooterhides footerfalsefalseBoolean
disableColumnReorderdisables column reorderingfalsefalseBoolean
disableColumnResizedisables column resizingfalsefalseBoolean
disableColumnPinningdisables column pinningfalsefalseBoolean
disableColumnFilterdisables column filteringfalsefalseBoolean
disableColumnSelectordisables column show and hidingfalsefalseBoolean
disableDensitySelectordisables changing of row densityfalsefalseBoolean
disableColumnMenudisables showing column menufalsefalseBoolean
disableMultipleColumnsSortingdisables sorting option in each columnfalsefalseBoolean
disableSearchdisables searchfalsefalseBoolean
disableColumnExportdisables column exportfalsefalseBoolean
fetchOnPageChangepage, rows per page or sorting change for paginated APInullfalseFunction
rowsCountshows rows count if it is paginated APIfalsefalseBoolean
customExportcustom export functionnullfalseBoolean

Example

...

import { ReactTabulous } from 'react-tabulous';
import { Button, IconButton, Select } from 'commonComponents/widgets';

...

const minAge = 20;
const maxAge = 80;

const workPlaceOptions = ['Bengaluru', 'Mumbai', 'Delhi', 'Chennai', 'Hyderabad'];

function generateUniqueId(): number {
	const random: number = Math.floor(Math.random() * 10000); // Generate a random number between 0 and 9999
	const id: string = random.toString().padStart(4, '0'); // Convert the random number to a string and ensure that it has exactly 4 digits
	return +id;
}

function getRandomBirthDate(): Date {
	const minYear: number = 1900;
	const minMonth: number = 0;
	const currentYear: number = new Date().getFullYear();
	const currentMonth: number = new Date().getMonth();
	const minDate: Date = new Date(minYear, minMonth, 1);
	const currentDate: Date = new Date(currentYear, currentMonth, 1);
	const diffTime: number = Math.abs(currentDate.getTime() - minDate.getTime());
	const diffDays: number = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
	const randomDays: number = Math.floor(Math.random() * diffDays);
	const randomDate: Date = new Date(minDate);
	randomDate.setDate(minDate.getDate() + randomDays);
	return randomDate;
}

const data = Array.from({ length: 50 }, (_, i) => {
	const id = generateUniqueId();

	return {
		id,
		name: `test${i + 1}`,
		email: `test${i + 1}@test.com`,
		age: Math.floor(Math.random() * (maxAge - minAge + 1)) + minAge,,
		birthDate: getRandomBirthDate(),
		level: Math.ceil(Math.random() * 3),
		workPlace: workPlaceOptions[Math.floor(Math.random() * workPlaceOptions.length)]
	};
});

const columns = [
	{
		field: 'id',
		headerName: 'ID',
		type: 'number',
		isFilterable: true,
		isSortable: true,
		isSearchable: true
	},
  {
		field: 'name',
		headerName: 'Name',
		type: 'string',
		isFilterable: true,
		isSortable: true,
		isSearchable: true
	},
  {
		field: 'age',
		headerName: 'Age',
		type: 'number',
		isFilterable: true,
		isSortable: true,
		isSearchable: true
	},
	{
		field: 'level',
		headerName: 'Level',
		type: 'string',
		renderCell: (row: any) => {
			const level = row?.level ?? 1;
			const levelText = level === 1 ? 'Beginner' : level === 2 ? 'Intermediate' : 'Advanced';
			const levelColor = level === 1 ? 'green' : level === 2 ? 'orange' : 'red';
			return <span style={{ color: levelColor }}>{levelText}</span>;
		},
		isFilterable: true,
		isSortable: true,
		isSearchable: true
	},
	{
		field: 'birthDate',
		headerName: 'Birth Date',
		type: 'date',
		isFilterable: true,
		isSortable: true,
		isSearchable: true
	},
  {
		field: 'email',
		headerName: 'Email Address',
		type: 'string',
		isFilterable: true,
		// isSortable: true,
		isSearchable: true
	},
  {
		field: 'workPlace',
		headerName: 'Work Place',
		type: 'string',
		renderCell: (row: any) => {
			const workPlace = row?.workPlace ?? '';

			const onChange = (event: any) => {
				console.log(event.target.value);
			};

			return <Select value={workPlace} options={workPlaceOptions} onChange={onChange} />;
		}
	},
  {
		field: 'action',
		headerName: 'Action',
		type: 'action',
		renderCell: (row: any) => {
			const onClick = () => {
				alert(JSON.stringify(row, null, 2));
				console.log(row);
			};

			return (
				<div style={{ display: 'flex' }}>
					<IconButton name="add" onClick={onClick} type="transparent" size={16} />
					<IconButton name="close" onClick={onClick} type="transparent" size={16} />
					<Button size="small" variant="contained" onClick={onClick}>
						Click
					</Button>
				</div>
			);
		}
	}
]

const customComponent = React.useCallback(
		(filteredAndSortedData: any, searchText: string, columns: any) => {
			return (
				<div>
					<Button
						onClick={() => {
							console.log('Button clicked', filteredAndSortedData, searchText, columns);
						}}
					>
						Create New User
					</Button>
				</div>
			);
		},
		[]
	);

...

<ReactTabulous
	data={data}
	columns={columns}
	emptyPlaceholder="N/A"
	checkboxSelection
	noRowsOverlay={<NoRowsOverlay />}
	defaultPageSize={50}
	bulkActions={['delete', 'edit']}
	onBulkActionClick={(action, selectedRows) => {
		console.log(action, selectedRows);
	}}
>
	{customComponent}
</ReactTabulous>

...

Contributing Guidelines

Please refer CONTRIBUTING.md

License

MIT License

4.0.0-beta-0.17

5 months ago

4.0.0-beta-0.3

10 months ago

4.0.0-beta-0.2

10 months ago

4.0.0-beta-0.5

10 months ago

4.0.0-beta-0.4

10 months ago

4.0.0-beta-0.1

10 months ago

4.0.0-beta-0.15

6 months ago

4.0.0-beta-0.16

6 months ago

4.0.0-beta-0.13

8 months ago

4.0.0-beta-0.14

6 months ago

4.0.0-beta-0.11

9 months ago

4.0.0-beta-0.7

10 months ago

4.0.0-beta-0.12

9 months ago

4.0.0-beta-0.6

10 months ago

4.0.0-beta-0.9

9 months ago

4.0.0-beta-0.10

9 months ago

4.0.0-beta-0.8

9 months ago

3.0.3

11 months ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

2 years ago

2.9.1

2 years ago

2.9.0

2 years ago

2.8.3

2 years ago

2.8.2

3 years ago

2.8.1

3 years ago

2.8.0

3 years ago

2.7.5-debug

3 years ago

2.7.7

3 years ago

2.7.6-debug.2

3 years ago

2.7.6-debug.1

3 years ago

2.7.6-debug

3 years ago

2.7.6

3 years ago

2.7.5

3 years ago

2.7.4

3 years ago

2.7.3

3 years ago

2.7.2

3 years ago

2.7.0

3 years ago

2.7.1

3 years ago

2.6.0

3 years ago

2.5.5

3 years ago

2.5.4

3 years ago

2.5.3

3 years ago

2.5.2

3 years ago

2.5.1

3 years ago

2.5.0

3 years ago

2.5.0-beta.4

3 years ago

2.5.0-beta.1

3 years ago

2.5.0-beta.2

3 years ago

2.5.0-beta.0

3 years ago

2.4.0

3 years ago

2.3.3

4 years ago

2.3.2

4 years ago

2.3.0

4 years ago

2.3.1

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.0.15

4 years ago

2.1.0

4 years ago

2.0.14

4 years ago

2.0.13

4 years ago

2.0.11

4 years ago

2.0.12

4 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.3

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.8

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago