You are currently viewing outdated (<=3.x) Chameleon documentation on our old website. For version >=4.x, check out our new website.

Current release: 3.5.0 | hub

components

Table (code)

A table is used to organise and display tabular data in a way that's easy to scan.

TitleAmount of page views
A very interesting article about fishes7,654,964
Look at this!13,223,568
How you can save the planet420
import { Table } from '@mediahuis/chameleon-react'

Props

NameTypeDefaultRequiredDescription
columnsArray<{ "title": "String" "field": "String" "textAlign": "'left''center''right'" "width": "String01234567891011'auto''full'" "colSpan": "Number" "ellipsis": "Boolean" }>---
dataArray<Object>---
emptyDescriptionString-true-
emptyIconFunctionStringNodeObjectSearch--
loadingBoolean--Show a loading state (e.g. while fetching data).
sortingBoolean---
tableLayout'auto''fixed''inherit''auto'--

System Props

System Props

Next to the properties listed in the propstable, a collection of system props can be added to any component for further general styling and layouting purposes. These props vary per component.

To read more about the system, click here to check out its dedicated page.

Columns

default: undefined

columns defines the upper row of the table and tells the table rows where to find the necessary data.

This is an array of objects, one for each column. The structure of that object is as follows:

  • title (required): The text that will be used in the table's header.
  • field (required): The key that corresponds to a key in the data array's objects.
  • textAlign (optional): How the column's text should be aligned.
TitleAmount of page views
No articles have been published

Data

default: undefined

Based on the fields defined in the columbs prop, the data object should be an array that has objects with keys corresponing to the keys you defined.

If a key would not exist on a row, a - character will be shown.

TitleAmount of page views
A very interesting article about fishes7,654,964
Look at this!13,223,568
No one likes me-

Empty table

emptyIcon default: Search

emptyDesciption default: undefined

If the data property is either not defined or an empty array, the table will show as empty. You can customize the empty display by using emptyDescription and emptyIcon.

TitleAmount of page views
No articles have been published

TableLayout

default: auto

Defines the algorithm used to lay out table cells, rows, and columns.

Col 1Col 2Col 3Col 4
A much longer piece of content for demo purposes. More goes here.Example textExample textExample text
Example textExample textExample textExample text
Col 1Col 2Col 3Col 4
A much longer piece of content for demo purposes. More goes here.Example textExample textExample text
Example textExample textExample textExample text

Column width

default: auto

Sets the width of the column. If you want to be sure to have a fixed width, use tableLayout fixed.

Col 1Col 2Col 3Col 4
This cell tries to be 700pxExample textExample textExample text
Example textExample textExample textExample text
Col 1Col 2Col 3Col 4
This is really 700pxExample textExample textExample text
Example textExample textExample textExample text

Ellipsis

default: undefined

If a collumn has ellipsis, overflowing texts will be cut and ellipsis will be added.

Col 1Ea aliqua sit do ullamco mollit esse duis adCol 3Col 4
Ea aliqua sit do ullamco mollit esse duis ad.Example textExample textExample text
Example textExample textExample textExample text

Sorting

default: undefined

The Table has a basic sorting feature that lets users sort data by any column. To make it possible, set the property sorting to true.

MarilynMonroe1926Los Angeles
AbrahamLincoln1809Hodgenville (Kentucky)
PaulMcCartney1942Liverpool

Non sorting columns

Make specific columns non-sortable by adding a sortable key to false. In the example below the Name field sortable is set to false.

Name
MarilynMonroe1926Los Angeles
AbrahamLincoln1809Hodgenville (Kentucky)
PaulMcCartney1942Liverpool

Component sorting not supported

The default sorting method is only limited to non component data and will cause errors when it tries to sort columns with components.That's why we recommend giving that specific column a sortable: false key.

Birthplace
MarilynMonroe1926
AbrahamLincoln1809
PaulMcCartney1942

Custom sorting

It's also possible to pass a customSort algorithm to specific columns. In the example below the new algorithm sorts by length of string of birthpllace.

MarilynMonroe1926Los Angeles
AbrahamLincoln1809Hodgenville (Kentucky)
PaulMcCartney1942Liverpool

© Copyright 2020 Mediahuis NV. All rights Reserved