Skip to content

Commit ddeff7b

Browse files
committed
feat(table): allow paths as attributes values on column definition
1 parent 39cb627 commit ddeff7b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

demo/TableExamples.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ export function TableExamples() {
5151
<div className="col mb-3">
5252
<h1 className="h4">Simple Table</h1>
5353
<Table
54-
columns={['a', 'b', 'c']}
54+
columns={['a', 'b', 'c.d']}
5555
docs={[
56-
{ a: 1, b: 2, c: 3 },
57-
{ a: 4, b: 5, c: 6 },
58-
{ a: 7, b: 8, c: 9 },
56+
{ a: 1, b: 2, c: { d: 3 } },
57+
{ a: 4, b: 5, c: { d: 6 } },
58+
{ a: 7, b: 8, c: { d: 9 } },
5959
]}
6060
/>
6161
</div>

src/table/TableBody.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { getColumnClass } from './table-helpers';
44
import { safeClick } from '../utils/event-handlers';
5+
import { getValueByPath } from '../utils/getters-setters';
56

67
export function TableBody({ columns, docs, rowClass, actions }) {
78
return (
@@ -42,7 +43,7 @@ TableBody.propTypes = {
4243
};
4344

4445
function getColumnValue(doc, column, docIndex) {
45-
const rawValue = doc[column.attribute];
46+
const rawValue = getValueByPath(doc, column.attribute);
4647

4748
if (!column.format) {
4849
return rawValue;

0 commit comments

Comments
 (0)