Skip to content

Commit 9dbb5b2

Browse files
committed
feat(SortableTables): Pass rowData prop into CustomCells
[finishes #113095437]
1 parent 3e121eb commit 9dbb5b2

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

library/spec/pivotal-ui-react/sortable-table/sortable-table_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ describe('SortableTable', function() {
257257
{
258258
attribute: 'title',
259259
displayName: 'Title',
260-
CustomCell: ({value, index}) => <td className="custom">{`${index}: ${value}`}</td>
260+
CustomCell: ({value, index, rowDatum}) => <td className="custom">{`${rowDatum.instances}-${index}: ${value}`}</td>
261261
},
262262
{
263263
attribute: 'instances',
@@ -288,9 +288,9 @@ describe('SortableTable', function() {
288288
});
289289

290290
it('uses custom for the column', function() {
291-
expect('tbody tr:nth-of-type(1) > td:eq(0)').toContainText('0: foo');
291+
expect('tbody tr:nth-of-type(1) > td:eq(0)').toContainText('1-0: foo');
292292
expect('tbody tr:nth-of-type(1) > td:eq(0)').toHaveClass('custom');
293-
expect('tbody tr:nth-of-type(2) > td:eq(0)').toContainText('1: sup');
293+
expect('tbody tr:nth-of-type(2) > td:eq(0)').toContainText('3-1: sup');
294294
expect('tbody tr:nth-of-type(2) > td:eq(0)').toHaveClass('custom');
295295
});
296296
});

library/src/pivotal-ui-react/sortable-table/sortable-table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const SortableTable = React.createClass({
7373
return sortedData.map((datum, rowKey) => {
7474
const cells = columns.map(({attribute, CustomCell}, key) => {
7575
const Cell = CustomCell || TableCell;
76-
return <Cell key={key} index={rowKey} value={datum[attribute]}>{datum[attribute]}</Cell>;
76+
return <Cell key={key} index={rowKey} value={datum[attribute]} rowDatum={datum}>{datum[attribute]}</Cell>;
7777
});
7878

7979
const Row = CustomRow || TableRow;

styleguide/docs/react/sortable-table.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ var CustomRow = React.createClass({
135135
The `TableCell` component is provided for users who wish to customize their cells
136136
with the `CustomCell` attribute on the `columns` prop. If a custom cell is provided, the table will use that
137137
component to render each cell, giving it a `value` prop representing the attribute from the datum for that row and `index`
138-
representing the (zero-indexed) row number.
138+
representing the (zero-indexed) row number. For more advanced use cases, the `rowDatum` prop is also passed into the custom cell.
139139
140140
Note that sorting occurs on the actual data.
141141
Changing the presentation of the data does not affect the sort behavior.
@@ -145,7 +145,7 @@ var CustomRow = React.createClass({
145145
render() {
146146
return (
147147
<TableCell>
148-
{this.props.index}: {this.props.value}
148+
{this.props.index}: {this.props.value} - {this.props.rowDatum.bar}
149149
</TableCell>
150150
);
151151
}

0 commit comments

Comments
 (0)