Skip to content

Commit

Permalink
added option row_single_select to enable single row selections when…
Browse files Browse the repository at this point in the history
… `row_selectable` is activated
  • Loading branch information
Martin Krey committed May 1, 2018
1 parent 8760034 commit 8e2bba5
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/components/DataTable.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,34 @@ class DataTable extends Component {
}
}

onRowsSelected(rows) {

this._absolute.selected_row_objects = R.union(
R.pluck('row', rows),
this._absolute.selected_row_objects
);
onRowsSelected(rowSelections) {
const rows = R.pluck('row', rowSelections);

if (this.props.row_single_select) {
// no action when try to select multiple elements like select all
if (R.length(rows) == 1) {
this._absolute.selected_row_objects = rows;

this.updateProps({
selected_row_indices: filterIndices(
this._absolute.selected_row_objects,
this.state.rows // only the visible rows
)
});
}
} else {
this._absolute.selected_row_objects = R.union(
rows,
this._absolute.selected_row_objects
);

this.updateProps({
selected_row_indices: filterIndices(
this._absolute.selected_row_objects,
this.state.rows // only the visible rows
)
});
this.updateProps({
selected_row_indices: filterIndices(
this._absolute.selected_row_objects,
this.state.rows // only the visible rows
)
});
}
}

onRowsDeselected(rowSelections) {
Expand Down Expand Up @@ -388,6 +403,7 @@ DataTable.propTypes = {

row_selectable: PropTypes.bool,
selected_row_indices: PropTypes.array,
row_single_select: PropTypes.bool,

// These props are passed directly into the component
enable_drag_and_drop: PropTypes.bool,
Expand Down Expand Up @@ -437,6 +453,7 @@ DataTable.defaultProps = {
filters: {},
selected_row_indices: [],
row_selectable: false,
row_single_select: false,
row_height: 35,
}

Expand Down

1 comment on commit 8e2bba5

@brendndavis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi - I tried using this - thought it just needed an overwrite of DataTable.react.js - but I get an error for unknown row_single_select argument - is there something else I need to do?

Please sign in to comment.