woocommerce/plugins/woocommerce-admin/client/components/table
Kelly Dwan f2e0165d5f Component – Table: Add compare checkboxes (https://github.com/woocommerce/woocommerce-admin/pull/389)
* Switch to withInstanceId higher order component

* Add checkboxes to the rows in a TableCard, if a compareBy prop is set

* Add Compare button to update query param

* Populate the selected rows from the query parameter

* Update compare filter display & selected table rows when the query changes

* Skip displaying tags if the label is null/undefined

* Style table header with compare button, search placeholder

* Prevent setting just an ID list as the state, as this will wipe out already-fetched tag labels

* Update docs

* Shortcut out of fetching tag labels if the query is empty
2018-09-18 10:12:13 -04:00
..
README.md Connect the revenue report to the api (https://github.com/woocommerce/woocommerce-admin/pull/316) 2018-09-03 11:25:38 -04:00
index.js Component – Table: Add compare checkboxes (https://github.com/woocommerce/woocommerce-admin/pull/389) 2018-09-18 10:12:13 -04:00
placeholder.js Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348) 2018-09-05 12:45:49 -04:00
style.scss Component – Table: Add compare checkboxes (https://github.com/woocommerce/woocommerce-admin/pull/389) 2018-09-18 10:12:13 -04:00
summary.js Docs Project: Add documentation parser + inline documentation (https://github.com/woocommerce/woocommerce-admin/pull/336) 2018-08-31 13:27:21 -04:00
table.js Component – Table: Add compare checkboxes (https://github.com/woocommerce/woocommerce-admin/pull/389) 2018-09-18 10:12:13 -04:00

README.md

Table Components

This is an accessible, sortable, and scrollable table for displaying tabular data (like revenue and other analytics data). It accepts headers for column headers, and rows for the table content. rowHeader can be used to define the index of the row header (or false if no header).

TableCard serves as Card wrapper & contains a card header, <Table />, <TableSummary />, and <Pagination />. This includes filtering and comparison functionality for report pages.

Table itself can be used outside of the Card + filtering context for displaying any tabular data.

TableSummary can also be used alone, and will display the list of data passed in on a single line.

TablePlaceholder behaves like Table but displays placeholder boxes instead of data. Can be used while loading.

How to use:

import { TableCard } from 'components/table';

render: function() {
  return (
    <TableCard
      title="Revenue Last Week"
      rows={ rows }
      headers={ headers }
      onQueryChange={ this.onQueryChange }
      query={ query }
      summary={ summary }
    />
  );
}

Props

TableCard props

  • headers: An array of column headers (see Table props).
  • onQueryChange: A function which returns a callback function to update the query string for a given param.
  • onClickDownload: A callback function which handles then "download" button press. Optional, if not used, the button won't appear.
  • query: An object of the query parameters passed to the page, ex { page: 2, per_page: 5 }.
  • rows (required): An array of arrays of display/value object pairs (see Table props).
  • rowHeader: Which column should be the row header, defaults to the first item (0) (see Table props).
  • summary: An array of objects with label & value properties, which display in a line under the table. Optional, can be left off to show no summary.
  • title (required): The title used in the card header, also used as the caption for the content in this table
  • totalRows (required): The total number of rows (across all pages).
  • rowsPerPage (required): The total number of rows to display per page.

rows, headers, rowHeader, and title are passed through to <Table />. summary is passed through as data to <TableSummary />. query.page, query.per_page, and onQueryChange are passed through to <Pagination />.

Table props

  • caption (required): A label for the content in this table
  • className: Optional additional classes
  • headers: An array of column headers, as objects with the following properties:
    • headers[].defaultSort: Boolean, true if this column is the default for sorting. Only one column should have this set.
    • headers[].isNumeric: Boolean, true if this column is a number value.
    • headers[].isSortable: Boolean, true if this column is sortable.
    • headers[].key: The API parameter name for this column, passed to orderby when sorting via API.
    • headers[].label: The display label for this column.
    • headers[].required: Boolean, true if this column should always display in the table (not shown in toggle-able list).
  • onSort: A function called when sortable table headers are clicked, gets the header.key as argument.
  • rows (required): An array of arrays of display/value object pairs. display is used for rendering, strings or elements are best here. value is used for sorting, and should be a string or number. A column with false value will not be sortable.
  • rowHeader: Which column should be the row header, defaults to the first item (0) (but could be set to 1, if the first col is checkboxes, for example). Set to false to disable row headers.

TableSummary props

  • data: An array of objects with label & value properties, which display on a single line.

TablePlaceholder props

  • caption (required): A label for the content in this table
  • headers: An array of column headers (see Table props).
  • numberOfRows: An integer with the number of rows to display. Defaults to 5.

Rows Format

Row data should be passed to the component as a list of arrays, where each array is a row in the table. Headers are passed in separately as an array of strings. For example, this data would render the following table.

Each row-cell should be an object with a display and value property, to enable consistent sortability.

const headers = [ 'Month', 'Orders', 'Revenue' ];
const rows = [
	[
		{ display: 'January', value: 1 },
		{ display: 10, value: 10 },
		{ display: '$530.00', value: 530 },
	],
	[
		{ display: 'February', value: 2 },
		{ display: 13, value: 13 },
		{ display: '$675.00', value: 675 },
	],
	[
		{ display: 'March', value: 3 },
		{ display: 9, value: 9 },
		{ display: '$460.00', value: 460 },
	],
]
Month Orders Revenue
January 10 $530.00
February 13 $675.00
March 9 $460.00