diff --git a/packages/dx-react-grid-bootstrap3/src/plugins/table-group-row.jsx b/packages/dx-react-grid-bootstrap3/src/plugins/table-group-row.jsx index 83d3c93fc2..5bb06fa8e0 100644 --- a/packages/dx-react-grid-bootstrap3/src/plugins/table-group-row.jsx +++ b/packages/dx-react-grid-bootstrap3/src/plugins/table-group-row.jsx @@ -1,15 +1,13 @@ import React from 'react'; import { TableGroupRow as TableGroupRowBase } from '@devexpress/dx-react-grid'; -import { TableGroupCell, TableGroupIndentCell } from '../templates/table-group-row-cell'; +import { TableGroupCell } from '../templates/table-group-row-cell'; const groupCellTemplate = props => ; -const groupIndentCellTemplate = props => ; export const TableGroupRow = props => ( diff --git a/packages/dx-react-grid-bootstrap3/src/plugins/table-view.jsx b/packages/dx-react-grid-bootstrap3/src/plugins/table-view.jsx index 92e5f1951d..1172a15365 100644 --- a/packages/dx-react-grid-bootstrap3/src/plugins/table-view.jsx +++ b/packages/dx-react-grid-bootstrap3/src/plugins/table-view.jsx @@ -4,10 +4,14 @@ import { combineTemplates } from '@devexpress/dx-react-core'; import { TableView as TableViewBase } from '@devexpress/dx-react-grid'; import { Table } from '../templates/table'; import { TableCell } from '../templates/table-cell'; +import { TableStubCell } from '../templates/table-stub-cell'; +import { TableStubHeaderCell } from '../templates/table-stub-header-cell'; import { TableNoDataCell } from '../templates/table-no-data-cell'; const tableTemplate = props => ; const defaultCellTemplate = props => ; +const stubCellTemplate = props => ; +const stubHeaderCellTemplate = props => ; const noDataCellTemplate = props => ; export const TableView = ({ tableCellTemplate, ...props }) => ( @@ -17,6 +21,8 @@ export const TableView = ({ tableCellTemplate, ...props }) => ( tableCellTemplate, defaultCellTemplate, )} + tableStubCellTemplate={stubCellTemplate} + tableStubHeaderCellTemplate={stubHeaderCellTemplate} tableNoDataCellTemplate={noDataCellTemplate} {...props} /> diff --git a/packages/dx-react-grid-bootstrap3/src/templates/table-filter-cell.jsx b/packages/dx-react-grid-bootstrap3/src/templates/table-filter-cell.jsx index c65ed1ce55..aa74bdb7b1 100644 --- a/packages/dx-react-grid-bootstrap3/src/templates/table-filter-cell.jsx +++ b/packages/dx-react-grid-bootstrap3/src/templates/table-filter-cell.jsx @@ -1,33 +1,29 @@ import React from 'react'; import PropTypes from 'prop-types'; -export const TableFilterCell = ({ style, column, filter, setFilter }) => ( +export const TableFilterCell = ({ style, filter, setFilter }) => ( ); TableFilterCell.propTypes = { - column: PropTypes.object, style: PropTypes.object, filter: PropTypes.object, setFilter: PropTypes.func, }; TableFilterCell.defaultProps = { - column: {}, style: null, filter: null, setFilter: () => {}, diff --git a/packages/dx-react-grid-bootstrap3/src/templates/table-group-row-cell.jsx b/packages/dx-react-grid-bootstrap3/src/templates/table-group-row-cell.jsx index c7e639d859..93fe1b7f90 100644 --- a/packages/dx-react-grid-bootstrap3/src/templates/table-group-row-cell.jsx +++ b/packages/dx-react-grid-bootstrap3/src/templates/table-group-row-cell.jsx @@ -37,25 +37,3 @@ TableGroupCell.defaultProps = { isExpanded: false, toggleGroupExpanded: () => {}, }; - -export const TableGroupIndentCell = ({ column, style }) => ( - -); - -TableGroupIndentCell.propTypes = { - style: PropTypes.object, - column: PropTypes.shape({ - width: PropTypes.number.isRequired, - }).isRequired, -}; - -TableGroupIndentCell.defaultProps = { - style: {}, -}; diff --git a/packages/dx-react-grid-bootstrap3/src/templates/table-stub-cell.jsx b/packages/dx-react-grid-bootstrap3/src/templates/table-stub-cell.jsx new file mode 100644 index 0000000000..68a526c7e5 --- /dev/null +++ b/packages/dx-react-grid-bootstrap3/src/templates/table-stub-cell.jsx @@ -0,0 +1,14 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +export const TableStubCell = ({ style }) => ( +
- {!column.type && ( - setFilter({ value: e.target.value })} - /> - )} + setFilter({ value: e.target.value })} + /> -   - +); + +TableStubCell.propTypes = { + style: PropTypes.shape(), +}; + +TableStubCell.defaultProps = { + style: null, +}; diff --git a/packages/dx-react-grid-bootstrap3/src/templates/table-stub-header-cell.jsx b/packages/dx-react-grid-bootstrap3/src/templates/table-stub-header-cell.jsx new file mode 100644 index 0000000000..91fd3e2fa9 --- /dev/null +++ b/packages/dx-react-grid-bootstrap3/src/templates/table-stub-header-cell.jsx @@ -0,0 +1,14 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +export const TableStubHeaderCell = ({ style }) => ( + +); + +TableStubHeaderCell.propTypes = { + style: PropTypes.shape(), +}; + +TableStubHeaderCell.defaultProps = { + style: null, +}; diff --git a/packages/dx-react-grid-material-ui/src/plugins/table-group-row.jsx b/packages/dx-react-grid-material-ui/src/plugins/table-group-row.jsx index 8260c60bd6..a8e78da743 100644 --- a/packages/dx-react-grid-material-ui/src/plugins/table-group-row.jsx +++ b/packages/dx-react-grid-material-ui/src/plugins/table-group-row.jsx @@ -1,15 +1,13 @@ import React from 'react'; import { TableGroupRow as TableGroupRowBase } from '@devexpress/dx-react-grid'; -import { TableGroupCell, TableGroupIndentCell } from '../templates/table-group-row-cell'; +import { TableGroupCell } from '../templates/table-group-row-cell'; const groupCellTemplate = props => ; -const groupIndentCellTemplate = props => ; export const TableGroupRow = props => ( diff --git a/packages/dx-react-grid-material-ui/src/plugins/table-view.jsx b/packages/dx-react-grid-material-ui/src/plugins/table-view.jsx index 49e40dfd1b..3313e96a42 100644 --- a/packages/dx-react-grid-material-ui/src/plugins/table-view.jsx +++ b/packages/dx-react-grid-material-ui/src/plugins/table-view.jsx @@ -4,10 +4,12 @@ import { combineTemplates } from '@devexpress/dx-react-core'; import { TableView as TableViewBase } from '@devexpress/dx-react-grid'; import { Table } from '../templates/table'; import { TableCell } from '../templates/table-cell'; +import { TableStubCell } from '../templates/table-stub-cell'; import { TableNoDataCell } from '../templates/table-no-data-cell'; const tableTemplate = props => ; const defaultCellTemplate = props => ; +const stubCellTemplate = props => ; const noDataCellTemplate = props => ; export const TableView = ({ tableCellTemplate, ...props }) => ( @@ -17,6 +19,8 @@ export const TableView = ({ tableCellTemplate, ...props }) => ( tableCellTemplate, defaultCellTemplate, )} + tableStubCellTemplate={stubCellTemplate} + tableStubHeaderCellTemplate={stubCellTemplate} tableNoDataCellTemplate={noDataCellTemplate} {...props} /> diff --git a/packages/dx-react-grid-material-ui/src/templates/table-filter-cell.jsx b/packages/dx-react-grid-material-ui/src/templates/table-filter-cell.jsx index a7bcba382f..1a9b08e4b5 100644 --- a/packages/dx-react-grid-material-ui/src/templates/table-filter-cell.jsx +++ b/packages/dx-react-grid-material-ui/src/templates/table-filter-cell.jsx @@ -16,24 +16,21 @@ const styleSheet = createStyleSheet('TableFilterCell', theme => ({ }, })); -const TableFilterCellBase = ({ style, column, filter, setFilter, classes }) => ( +const TableFilterCellBase = ({ style, filter, setFilter, classes }) => ( - {!column.type && ( - setFilter({ value: e.target.value })} - /> - )} + setFilter({ value: e.target.value })} + /> ); TableFilterCellBase.propTypes = { - column: PropTypes.object, style: PropTypes.object, filter: PropTypes.object, setFilter: PropTypes.func, @@ -41,7 +38,6 @@ TableFilterCellBase.propTypes = { }; TableFilterCellBase.defaultProps = { - column: {}, style: null, filter: null, setFilter: () => {}, diff --git a/packages/dx-react-grid-material-ui/src/templates/table-group-row-cell.jsx b/packages/dx-react-grid-material-ui/src/templates/table-group-row-cell.jsx index 56245d40fd..c41c8b9972 100644 --- a/packages/dx-react-grid-material-ui/src/templates/table-group-row-cell.jsx +++ b/packages/dx-react-grid-material-ui/src/templates/table-group-row-cell.jsx @@ -74,30 +74,3 @@ TableGroupCellBase.defaultProps = { }; export const TableGroupCell = withStyles(styleSheet)(TableGroupCellBase); - -const TableGroupIndentCellBase = ({ column, style, classes }) => ( - -   - -); - -TableGroupIndentCellBase.propTypes = { - style: PropTypes.object, - column: PropTypes.shape({ - width: PropTypes.number.isRequired, - }).isRequired, - classes: PropTypes.object.isRequired, -}; - -TableGroupIndentCellBase.defaultProps = { - style: {}, -}; - -export const TableGroupIndentCell = withStyles(styleSheet)(TableGroupIndentCellBase); - diff --git a/packages/dx-react-grid-material-ui/src/templates/table-stub-cell.jsx b/packages/dx-react-grid-material-ui/src/templates/table-stub-cell.jsx new file mode 100644 index 0000000000..61294bc2e8 --- /dev/null +++ b/packages/dx-react-grid-material-ui/src/templates/table-stub-cell.jsx @@ -0,0 +1,28 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { TableCell } from 'material-ui'; +import { withStyles, createStyleSheet } from 'material-ui/styles'; + +const styleSheet = createStyleSheet('TableStubCell', () => ({ + cell: { + padding: 0, + }, +})); + +const TableStubCellBase = ({ style, classes }) => ( + +); + +TableStubCellBase.propTypes = { + style: PropTypes.object, + classes: PropTypes.object.isRequired, +}; + +TableStubCellBase.defaultProps = { + style: {}, +}; + +export const TableStubCell = withStyles(styleSheet)(TableStubCellBase); diff --git a/packages/dx-react-grid/docs/reference/table-group-row.md b/packages/dx-react-grid/docs/reference/table-group-row.md index e8ee6afde6..4497265d5f 100644 --- a/packages/dx-react-grid/docs/reference/table-group-row.md +++ b/packages/dx-react-grid/docs/reference/table-group-row.md @@ -14,21 +14,21 @@ A plugin that renders group rows with the capability to expand and collapse them Name | Type | Default | Description -----|------|---------|------------ groupCellTemplate | (args: [GroupCellArgs](#group-cell-args)) => ReactElement | | A component that renders a group row -groupIndentCellTemplate | (args: [GroupIndentCellArgs](#group-indent-cell-args)) => ReactElement | | A component that renders a group indent cell +groupIndentCellTemplate | (args: [GroupIndentCellArgs](#group-indent-cell-args)) => ReactElement | null | A component that renders a group indent cell groupIndentColumnWidth | number | | Width of the group indent columns ## Interfaces ### GroupCellArgs -Describes properties passed to the template that renders a group row. +Describes the properties passed to the template that renders a group row. A value with the following shape: Field | Type | Description ------|------|------------ row | [GroupRow](#group-row) | A group row data object -isExpanded | boolean | Specifies whether or not a row is expanded +isExpanded | boolean | Specifies if a row is expanded toggleGroupExpanded | () => void | Toggles the expanded state of a group row ### GroupIndentCellArgs diff --git a/packages/dx-react-grid/docs/reference/table-view.md b/packages/dx-react-grid/docs/reference/table-view.md index 67d1ec95b1..985e159561 100644 --- a/packages/dx-react-grid/docs/reference/table-view.md +++ b/packages/dx-react-grid/docs/reference/table-view.md @@ -15,25 +15,27 @@ Name | Type | Default | Description -----|------|---------|------------ tableTemplate | (args: [TableArgs](#table-args)) => ReactElement | | Renders a table using the specified parameters tableCellTemplate | (args: [TableCellArgs](#table-cell-args)) => ReactElement | | Renders a table cell using the specified parameters -tableNoDataCellTemplate | (args: Object) => ReactElement | | Renders a table cell for an empty state using the specified parameters -allowColumnReordering | boolean | false | If true, allows an end-user to change the column order by dragging +tableNoDataCellTemplate | (args: [TableNoDataCellArgs](#table-no-data-cell-args)) => ReactElement | | Renders a table cell using the specified parameters when the table is empty +tableStubCellTemplate | (args: [TableStubCellArgs](#table-stub-cell-args)) => ReactElement | | Renders a stub table cell if the cell data is not provided +tableStubHeaderCellTemplate | (args: [TableStubHeaderCellArgs](#table-stub-header-cell-args)) => ReactElement | | Renders a stub header cell if the cell data is not provided +allowColumnReordering | boolean | false | If true, allows an end-user to change the column's order by dragging it ## Interfaces ### TableArgs -Describes properties passed to the table template when it is being rendered +Describes properties passed to the table template when it is being rendered. Field | Type | Description ------|------|------------ -headerRows | Array<[TableRow](#table-row)> | Specifies rows that should be rendered within the table header -bodyRows | Array<[TableRow](#table-row)> | Specifies rows that should be rendered within the table body +headerRows | Array<[TableRow](#table-row)> | Specifies rows rendered in the table header +bodyRows | Array<[TableRow](#table-row)> | Specifies rows rendered in the table body columns | Array<[TableColumn](#table-column)> | Specifies the rendered table columns -cellTemplate | (args: [CellArgs](#cell-args)) => ReactElement | The template that should be used to render table cells +cellTemplate | (args: [CellArgs](#cell-args)) => ReactElement | The template used to render table cells ### CellArgs -Describes properties passed to a cell template when it is being rendered +Describes properties passed to a cell template when it is being rendered. A value with the following shape: @@ -41,19 +43,46 @@ Field | Type | Description ------|------|------------ row | [TableRow](#table-row) | Specifies a table row column | [TableColumn](#table-column) | Specifies a table column +style? | Object | Specifies cell styles ### TableCellArgs -Describes properties passed to the table cell template when it is being rendered +Describes properties passed to the table cell template when it is being rendered. Field | Type | Description ------|------|------------ row | [TableRow](#table-row) | Specifies a table row column | [TableColumn](#table-column) | Specifies a table column +style? | Object | Specifies cell styles + +### TableNoDataCellArgs + +Describes properties passed to the table cell being rendered when using an empty template. + +Field | Type | Description +------|------|------------ +style? | Object | Specifies cell styles +colspan? | number | Specifies the number of columns the cell spans + +### TableStubCellArgs + +Describes properties passed to the stub table cell template being rendered. + +Field | Type | Description +------|------|------------ +style? | Object | Specifies cell styles + +### TableStubHeaderCellArgs + +Describes properties passed to the stub header cell template being rendered. + +Field | Type | Description +------|------|------------ +style? | Object | Specifies cell styles ### TableRow -Describes properties of a table row that is rendered by the TableView plugin +Describes properties of a table row rendered by the TableView plugin. Extends [Row](grid.md#row) @@ -61,11 +90,11 @@ A value with the following shape: Field | Type | Description ------|------|------------ -type? | string | Specifies the table row type. Used to identify a cell template for a rendered row. The type is not defined for rows passed by a user. +type? | string | Specifies the table row type. Defines a cell template used to render a row. The type is not defined for rows passed by a user. ### TableColumn -Describes table column properties taken into account by the TableView plugin +Describes table column properties that the TableView plugin takes into account. Extends [Column](grid.md#column) @@ -73,7 +102,7 @@ A value with the following shape: Field | Type | Description ------|------|------------ -type? | string | Specifies the table column type. Used to identify a cell template to render a column cell. The type property is not defined for data rows +type? | string | Specifies the table column type. Defines a cell template used to render a cell. The type is not defined for data rows ## Plugin Developer Reference @@ -91,6 +120,5 @@ Name | Plugin | Type | Description tableHeaderRows | Getter | () => Array<[TableRow](#table-row)> | Rows to be rendered inside the table header tableBodyRows | Getter | () => Array<[TableRow](#table-row)> | Rows to be rendered inside the table body tableColumns | Getter | () => Array<[TableColumn](#table-column)> | Columns to be rendered inside the table -tableExtraProps | Getter | () => { [key: string]: any } | Additional table properties that can be provided by other plugins -tableView | Template | | A template that renders a table +tableExtraProps | Getter | () => { [key: string]: any } | Additional table properties that other plugins can provide tableViewCell | Template | { row: [TableRow](#table-row), column: [TableColumn](#table-column) } | A template that renders a table cell diff --git a/packages/dx-react-grid/src/plugins/table-filter-row.jsx b/packages/dx-react-grid/src/plugins/table-filter-row.jsx index acfb711dee..e5f3336262 100644 --- a/packages/dx-react-grid/src/plugins/table-filter-row.jsx +++ b/packages/dx-react-grid/src/plugins/table-filter-row.jsx @@ -20,7 +20,7 @@ export class TableFilterRow extends React.PureComponent { - + {groupIndentCellTemplate && ( + + )} ); } @@ -56,6 +58,10 @@ export class TableGroupRow extends React.PureComponent { TableGroupRow.propTypes = { groupCellTemplate: PropTypes.func.isRequired, - groupIndentCellTemplate: PropTypes.func.isRequired, + groupIndentCellTemplate: PropTypes.func, groupIndentColumnWidth: PropTypes.number.isRequired, }; + +TableGroupRow.defaultProps = { + groupIndentCellTemplate: null, +}; diff --git a/packages/dx-react-grid/src/plugins/table-group-row.test.jsx b/packages/dx-react-grid/src/plugins/table-group-row.test.jsx new file mode 100644 index 0000000000..0d8bc6adbf --- /dev/null +++ b/packages/dx-react-grid/src/plugins/table-group-row.test.jsx @@ -0,0 +1,76 @@ +import React from 'react'; +import { mount } from 'enzyme'; + +import { setupConsole } from '@devexpress/dx-testing'; +import { + Template, TemplatePlaceholder, PluginHost, +} from '@devexpress/dx-react-core'; + +import { TableGroupRow } from './table-group-row'; + +describe('TableGroupRow', () => { + let resetConsole; + beforeAll(() => { + resetConsole = setupConsole({ ignore: ['validateDOMNesting'] }); + }); + + afterAll(() => { + resetConsole(); + }); + + const testIndentCell = ({ + cellParams, + shouldRender, + template = () =>
, + }) => { + const tree = mount( + + + null} + groupIndentColumnWidth={40} + groupIndentCellTemplate={template} + /> + , + ); + + expect(tree.find('td.group-indent').exists()) + .toBe(shouldRender); + }; + + it('should render indent cell in a group column intersection with a foreign group row', () => { + testIndentCell({ + cellParams: { + column: { type: 'groupColumn', group: { columnName: 'a' } }, + row: { type: 'groupRow', column: { name: 'b' } }, + }, + shouldRender: true, + }); + }); + + it('should render indent cell in a group column intersection with a data row', () => { + testIndentCell({ + cellParams: { + column: { type: 'groupColumn', group: { columnName: 'a' } }, + row: { id: 1 }, + }, + shouldRender: true, + }); + }); + + it('should not render indent cell if it is undefined', () => { + testIndentCell({ + cellParams: { + column: { type: 'groupColumn', group: { columnName: 'a' } }, + row: { id: 1 }, + }, + template: null, + shouldRender: false, + }); + }); +}); diff --git a/packages/dx-react-grid/src/plugins/table-header-row.jsx b/packages/dx-react-grid/src/plugins/table-header-row.jsx index 941798e6bb..66823569ef 100644 --- a/packages/dx-react-grid/src/plugins/table-header-row.jsx +++ b/packages/dx-react-grid/src/plugins/table-header-row.jsx @@ -18,17 +18,15 @@ export class TableHeaderRow extends React.PureComponent { />