1.1.43 • Published 1 month ago

qbs-react-grid v1.1.43

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

QbsTable Component

npm install qbs-react-grid
import { QbsTable } from 'qbs-react-grid';
import 'qbs-react-grid/dist/css/qbs-react-grid.css';

<QbsTable data={[{ id: 1, name: 'John Doe' }]} columns={[{ title: 'Name', field: 'name' }]} />;

Description

QbsTable is a versatile and customizable table component designed to display tabular data efficiently. It provides features like sorting, column grouping, and various cell customizations.

Props

QbsTableProps

PropTypeDescription
columnsreadonly QbsColumnProps[]Defines each column in the table.
datareadonly any[]Data objects to be displayed in the table rows.
actionPropsreadonly ActionProps[]Defines actions for each row.
isTreebooleanSpecifies if the table should render as a tree.
paginationbooleanEnables pagination for the table.
paginationPropsPaginationPropsControls pagination properties.
handleColumnSort(sortColumn: string, sortType: string) => voidHandles column sorting.
sortType'desc' \| 'asc'Defines the sorting type.
sortColumnstringDefines the column being sorted.
selectionbooleanEnables row selection.
onSelect(keys: any[]) => voidCalled when rows are selected.
titlestringSpecifies the table title.
searchbooleanEnables search functionality.
onSearch(key?: string) => voidCalled when a search is performed.
asyncSearchbooleanIf true, the search will be asynchronous.
searchValuestringRepresents the current value in the search input.
handleSearchValue(value?: string) => voidHandles search input changes.
themestringDefines the theme applied to the table.
onRowClick(data: any) => voidCalled when a row is clicked.
cellBorderedbooleanIf true, each cell will have a border.
borderedbooleanIf true, the table will have a border.
heightnumberDefines the table height.
minHeightnumberDefines the minimum table height.
maxHeightnumber \| stringDefines the maximum table height.
wordWrapboolean \| 'break-all' \| 'break-word' \| 'keep-all' \| undefinedDefines the word wrap style for the content in a cell.
dataRowKeystringDefines the key field in the data.
onExpandChange(expanded: boolean, rowData: any) => voidCalled when a row expands or collapses.
defaultExpandAllRowsbooleanIf true, all rows will be expanded by default.
expandedRowKeysreadonly number[]Contains the array of expanded row keys.
setExpandedRowKeys(value: readonly number[]) => voidSets expanded row keys.
handleMenuActions(actions: ActionProps, rowData: any) => voidHandles menu actions.
handleRowExpanded(rowData: any) => React.ReactNodeRenders expanded row content.
shouldUpdateScrollbooleanIf true, the table will update the scroll position on data or size change.
rowExpandbooleanEnables row expand functionality.
primaryFilterReactElement \| ReactNodeDefines the primary filter component.
advanceFilterReactElement \| ReactNodeDefines the advanced filter component.

QbsColumnProps

PropTypeDescription
titlestringTitle of the column.
fieldstringField in the data that this column represents.
sortablebooleanSpecifies if the column is sortable.
resizablebooleanSpecifies if the column is resizable.
fixedbooleanIf true, the column will be fixed on horizontal scrolling.
alignAlignAlignment of the column content. Supports 'center', 'left', 'right'.
colWidthnumberWidth of the column.
renderCell(rowData: any) => ReactElementRenders custom cell content.
customCellbooleanIf true, a custom cell will be rendered using renderCell.
groupedbooleanIf true, the column will be grouped with the groupheader.
groupheaderstringThe header of the grouped column.
childrenreadonly ColumnBase[]Child columns of the grouped column.

PaginationProps

PropTypeDescription
totalnumberTotal number of items.
rowsPerPagenumberNumber of rows per page.
dropOptionsnumber[]Drop-down options for rows per page.
currentPagenumberCurrent active page.
maxPagenumberMaximum number of pages.
onRowsPerPage(row: number, page: number) => voidFunction called when rows per page is changed.
onPagination(row: number, page: number) => voidFunction called when pagination is changed.

ActionProps

PropTypeDescription
titlestringTitle of the action.
action(row: any) => voidFunction to be executed when the action is triggered.
iconReact.ReactNodeIcon to be displayed for the action.
toolTipstringTooltip text for the action.

QbsTableToolbarProps

PropTypeDescription
titlestringTitle of the toolbar.
searchbooleanEnables search functionality in the toolbar.
onSearch(key?: string) => voidFunction called when a search is performed from the toolbar.
asyncSearchbooleanIf true, search will be asynchronous.
searchValuestringCurrent value in the search input.
handleSearchValue(value?: string) => voidFunction to handle search

Props Examples

handleColumnSort: (sortColumn: any, sortType: any) => void

A function to handle the column sorting. It receives sortColumn and sortType as parameters.

<QbsTable handleColumnSort={(sortColumn, sortType) => console.log(sortColumn, sortType)} />

data: any[]

An array containing the data to be displayed in the table.

<QbsTable data={[{ id: 1, name: 'John Doe' }]} />

columns: Column[]

An array defining the columns of the table.

<QbsTable columns={[{ title: 'Name', field: 'name' }]} />

sortColumn: string

Defines the column that is currently sorted.

<QbsTable sortColumn="name" />

sortType: string

Defines the current sort type.

<QbsTable sortType="asc" />

selection: boolean

Enables or disables row selection using checkboxes.

<QbsTable selection={true} />

onSelect: (selectedKeys: number[]) => void

Callback fired when a row is selected.

<QbsTable onSelect={selectedKeys => console.log(selectedKeys)} />

title: string

Sets the title of the table.

<QbsTable title="My Custom Table" />

search: boolean

Enables or disables the search functionality.

<QbsTable search={true} />

asyncSearch: boolean

If true, activates asynchronous search.

<QbsTable asyncSearch={true} />

searchValue: string

Controls the value of the search input.

<QbsTable searchValue="John" />

onSearch: (value: string) => void

Callback fired when the search value changes.

<QbsTable onSearch={value => console.log(value)} />

handleSearchValue: (value: string) => void

A function to handle the search value, usually used for controlled components.

<QbsTable handleSearchValue={value => console.log(value)} />

paginationProps: object

Props to be passed to the Pagination component.

<QbsTable paginationProps={{ total: 100, pageSize: 10 }} />

pagination: boolean

Enables or disables the pagination.

<QbsTable pagination={true} />

cellBordered: boolean

If true, displays borders around cells.

<QbsTable cellBordered={true} />

bordered: boolean

If true, displays a border around the table.

<QbsTable bordered={true} />

minHeight: number

Sets the minimum height of the table.

<QbsTable minHeight={300} />

height: number

Sets the height of the table.

<QbsTable height={550} />

onExpandChange: (rowData: any) => void

Callback fired when the expanded state of a row is changed.

<QbsTable onExpandChange={rowData => console.log(rowData)} />

wordWrap: boolean

If true, enables word wrapping in cells.

<QbsTable wordWrap={true} />

dataRowKey: string

Defines the key from the data that will be used for row keys.

<QbsTable dataRowKey="id" />

defaultExpandAllRows: boolean

If true, expands all rows by default.

<QbsTable defaultExpandAllRows={true} />

handleRowExpanded: (rowData: any) => ReactNode

A function to handle the rendering of expanded rows. It should return a valid ReactNode.

<QbsTable handleRowExpanded={rowData => <div>{rowData.name}</div>} />

shouldUpdateScroll: boolean

If true, updates the scroll position when needed.

<QbsTable shouldUpdateScroll={true} />

rowExpand: boolean

If true, enables the row expand functionality.

<QbsTable rowExpand={true} />

actionProps: any[]

An array of action props to be passed to the ActionCell component.

<QbsTable actionProps={[{ title: 'Delete', onClick: rowData => console.log(rowData) }]} />

theme: string

Defines the theme of the table. It could be 'light' or 'dark'.

<QbsTable theme="dark" />

handleMenuActions: (action: any, rowData: any) => void

A function to handle the actions from the action menu.

<QbsTable handleMenuActions={(action, rowData) => console.log(action, rowData)} />

onRowClick: (rowData: any) => void

Callback fired when a row is clicked.

<QbsTable onRowClick={rowData => console.log(rowData)} />

expandedRowKeys: string[]

An array of the keys of the currently expanded rows.

<QbsTable expandedRowKeys={['1', '2']} />

setExpandedRowKeys: (keys: string[]) => void

A function to set the keys of the currently expanded rows.

<QbsTable setExpandedRowKeys={keys => console.log(keys)} />

primaryFilter: any

Prop to handle primary filtering.

<QbsTable primaryFilter={{ filterType: 'date', filterValue: '2023-01-01' }} />

advancefilter: any

Prop to handle advanced filtering.

<QbsTable advancefilter={{ filterType: 'name', filterValue: 'John' }} />

classes: object

Object containing className strings.

<QbsTable classes={{ headerClass: 'my-header-class', cellClass: 'my-cell-class' }} />

toolbar: boolean

If true, displays the toolbar.

<QbsTable toolbar={true} />

Example

Here is an example of how you might use the QbsTable component with various props:

<QbsTable
  title="User Data"
  data={[
    { id: 1, name: 'Quinoid' },
    { id: 2, name: 'Quinoid1' }
  ]}
  columns={[{ title: 'Name', field: 'name' }]}
  sortColumn="name"
  sortType="asc"
  selection={true}
  onSelect={selectedKeys => console.log(selectedKeys)}
  search={true}
  onSearch={value => console.log(value)}
  pagination={true}
  paginationProps={{ total: 100, pageSize: 10 }}
  cellBordered={true}
  bordered={true}
  minHeight={300}
  height={550}
  onExpandChange={rowData => console.log(rowData)}
  wordWrap={true}
  dataRowKey="id"
  defaultExpandAllRows={true}
  handleRowExpanded={rowData => <div>{rowData.name}</div>}
  shouldUpdateScroll={true}
  rowExpand={true}
  actionProps={[{ title: 'Delete', onClick: rowData => console.log(rowData) }]}
  theme="dark"
  handleMenuActions={(action, rowData) => console.log(action, rowData)}
  onRowClick={rowData => console.log(rowData)}
  expandedRowKeys={['1', '2']}
  setExpandedRowKeys={keys => console.log(keys)}
  primaryFilter={{ filterType: 'date', filterValue: '2023-01-01' }}
  advancefilter={{ filterType: 'name', filterValue: 'John' }}
  classes={{ headerClass: 'my-header-class', cellClass: 'my-cell-class' }}
  toolbar={true}
/>

Notes

  • The QbsTable component should be used in accordance with the requirements of your application. Ensure that you pass the correct props for your desired functionality.
  • Please ensure that you have handled the callback functions properly for your specific use cases, as mismanagement of state and props may lead to unexpected behavior of the component.

classes Prop

The classes prop is an object where keys are the names of elements or parts of the QbsTable component, and values are the class names you want to apply. Below is the list of keys you can use:

  • headerClass: Class applied to the header cells of the table. It affects both grouped and ungrouped headers.

  • cellClass: Class applied to the data cells of the table.

  • tableContainerClass: Class applied to the container wrapping the whole table, including the toolbar.

  • headerlClass: Class applied to the specific header cells, especially when using features like row expansion and selection.

  • selectionCell: Class applied to the container of the checkbox in the header when selection is enabled.

  • tableCheckBoxClass: Class applied to the checkboxes in the rows and the header when selection is enabled.

  • actionCellClass: Class applied to the action cells in the table when actions are provided.

  • toolbarClass: Class applied to table toolbar

Example Usage

<QbsTable
  classes={{
    headerClass: 'my-header-class',
    cellClass: 'my-cell-class',
    tableContainerClass: 'my-table-container-class',
    headerlClass: 'my-headerl-class',
    selectionCell: 'my-selection-cell-class',
    tableCheckBoxClass: 'my-table-check-box-class',
    actionCellClass: 'my-action-cell-class'
  }}
  //... other props
/>

1. .qbs-table

  • Defines the main container for the table.
.qbs-table-toolbar
  • Height: 58px.
  • Display: Flex.
  • Describes the toolbar located above the table containing various controls like filters and search.
  • Children:
    • .start-container: Container aligning child elements to the start.
    • .end-container: Container aligning child elements to the end, contains .rows-count for displaying row count with padding 0px 10px.
.sub-qbs-table-toolbar
  • Display: Flex.
  • Styling for sub-toolbar located beneath the main toolbar.
.qbs-table-search-container
  • Position: Relative.
  • Container for search input and related buttons.
  • Children:
    • .input: Minimal design search input, height: 32px, border-radius: 4px, min-width: 200px.
    • .search-button and .close-button: Positioned absolute and styled with a grey color and white background.

2. .qbs-tabledata-theme='dark'

  • Applies when the table is in dark theme mode, changing background color to #333333 and font color to #ffffff.

3. .rs-table-cell-contentdata-theme='dark'

  • Similar to .qbs-tabledata-theme='dark', but applied to table cell content in dark theme.

4. .qbs-table-menu-dropdown

  • Position: Relative.
  • Display: Inline-block.
  • Contains dropdown-related elements.
.qbs-table-dropbtn
  • Button to trigger the dropdown, it's styled with a transparent background, black color font, and a cursor set to pointer.
.qbs-table-qbs-table-menu-dropdown-content
  • Positioned absolute, contains dropdown items styled with a light (#f1f1f1) background color and black text.

5. .qbs-table-tooltip

  • Position: Relative.
  • Display: Inline-block.
  • Cursor: Pointer.
  • Contains tooltip text which is hidden by default and visible on hover with a smooth opacity transition.

6. .rs-table-row

  • Overflow: Visible !important.
  • Ensures the rows of the table are visible.

Qbs-Table-Custom-Pagination Styles

1. .qbs-table-custom-pagination

  • Display: Flex.
  • Justify-Content: Space-between.
  • Padding: 10px.
  • Border: 1px solid.
  • Min-Height: 40px.
  • Align-Items: Center.
  • Describes the main container for custom pagination, ensuring items are spaced evenly and aligned centrally.
&-header
  • Border-Bottom: 1px solid #eee.
  • Position: Absolute.
  • Width: 100%.
  • Acts as the header for the pagination container with a solid bottom border.
    • &-content: Styled as a table cell, providing padding of 8px around the content.
.qbs-table-pagination-dropdown
  • Width: Auto.
  • Border-Radius: 6px.
  • Height: 30px.
  • Display: Flex.
  • Align-Items: Center.
  • Justify-Content: Center.
  • Describes the dropdown within the pagination, allowing flex display with centered items.
.qbs-table-icon-container
  • Padding: 5px.
  • Cursor: Pointer.
  • Display: Flex.
  • Justify-Items: Center.
  • Align-Items: Center.
  • Color: Black.
  • Height: 100%.
  • Background-Color: Transparent.
  • Stylish container for icons. It changes color to blue when hovered and to grey when disabled.
.qbs-table-pagination-right-block
  • Display: Flex.
  • Align-Items: Center.
  • Acts as the right block container of the pagination section.
    • .block-container: Flex container that holds block items.
    • .block-item: Individual block items, stylized with a cursor pointer, centered alignment, and bordered. It changes the border and text color to blue when hovered or active.
    • .selected: Representing the selected item, enhancing the border and changing the color to blue.

Installation

npm install qbs-react-grid
1.1.43

1 month ago

1.1.42

1 month ago

1.1.41

2 months ago

1.1.39

2 months ago

1.1.40

2 months ago

1.1.38

2 months ago

1.1.37

3 months ago

1.1.36

3 months ago

1.1.35

3 months ago

1.1.33

3 months ago

1.1.29

3 months ago

1.1.30

3 months ago

1.1.32

3 months ago

1.1.31

3 months ago

1.1.28

4 months ago

1.1.27

4 months ago

1.1.26

4 months ago

1.1.25

4 months ago

1.1.24

4 months ago

1.1.23

4 months ago

1.1.22

4 months ago

1.1.21

4 months ago

1.1.19

5 months ago

1.1.18

5 months ago

1.1.17

5 months ago

1.1.20

5 months ago

1.1.16

5 months ago

1.1.15

5 months ago

1.1.14

5 months ago

1.1.12

5 months ago

1.1.13

5 months ago

1.1.9

5 months ago

1.1.8

5 months ago

1.1.11

5 months ago

1.1.10

5 months ago

1.1.7

5 months ago

1.1.6

5 months ago

1.1.5

5 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.2

5 months ago

1.0.19

7 months ago

1.0.18

7 months ago

1.0.17

7 months ago

1.0.16

7 months ago

1.0.21

7 months ago

1.0.20

7 months ago

1.0.26

7 months ago

1.0.25

7 months ago

1.0.24

7 months ago

1.0.23

7 months ago

1.0.29

7 months ago

1.0.28

7 months ago

1.0.27

7 months ago

1.0.33

7 months ago

1.0.32

7 months ago

1.0.31

7 months ago

1.0.30

7 months ago

1.0.37

7 months ago

1.0.36

7 months ago

1.0.35

7 months ago

1.0.34

7 months ago

1.1.1

5 months ago

1.1.0

6 months ago

1.0.39

6 months ago

1.0.38

7 months ago

1.0.40

6 months ago

1.0.44

6 months ago

1.0.43

6 months ago

1.0.42

6 months ago

1.0.41

6 months ago

1.0.48

6 months ago

1.0.47

6 months ago

1.0.46

6 months ago

1.0.45

6 months ago

1.0.49

6 months ago

1.0.51

6 months ago

1.0.50

6 months ago

1.0.15

7 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.14

8 months ago

1.0.13

8 months ago

1.0.12

8 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago