Skip to content

Commit

Permalink
Merge pull request #1438 from wdh2100/enhancement/rowSelected
Browse files Browse the repository at this point in the history
Enhancement/rowSelected options
  • Loading branch information
patorjk authored Jul 24, 2020
2 parents b5697f3 + b2411a9 commit d1c979e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ The component accepts the following props:
|**`rowsExpanded`**|array||User provided expanded rows.
|**`rowsPerPage`**|number|10|Number of rows allowed per page.
|**`rowsPerPageOptions`**|array|[10,15,100]|Options to provide in pagination for number of rows a user can select.
|**`rowsSelected`**|array||User provided selected rows.
|**`rowsSelected`**|array||User provided selected rows (must be provided an array of numbers only)
|**`search`**|boolean|true|Show/hide search icon from toolbar.
|**`searchPlaceholder`**|string||Search text placeholder. [Example](https://github.com/gregnb/mui-datatables/blob/master/examples/customize-search/index.js)
|**`searchProps`**|object|{}|Props applied to the search text box. You can set method callbacks like onBlur, onKeyUp, etc, this way. [Example](https://github.com/gregnb/mui-datatables/blob/master/examples/customize-search/index.js)
Expand Down
27 changes: 16 additions & 11 deletions src/MUIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,9 @@ class MUIDataTable extends React.Component {
if (options.expandableRows && options.renderExpandableRow === undefined) {
throw Error('renderExpandableRow must be provided when using expandableRows option');
}
if (options.rowsSelected && Array.isArray(options.rowsSelected) && options.rowsSelected.some(isNaN)) {
warnInfo('When using the rowsSelected option, must be provided an array of numbers only.');
}
}

setTableAction = action => {
Expand Down Expand Up @@ -799,19 +802,21 @@ class MUIDataTable extends React.Component {
if (TABLE_LOAD.INITIAL) {
// Multiple row selection customization
if (this.options.rowsSelected && this.options.rowsSelected.length && this.options.selectableRows === 'multiple') {
this.options.rowsSelected.forEach(row => {
let rowPos = row;

for (let cIndex = 0; cIndex < this.state.displayData.length; cIndex++) {
if (this.state.displayData[cIndex].dataIndex === row) {
rowPos = cIndex;
break;
this.options.rowsSelected
.filter(selectedRowIndex => selectedRowIndex === 0 || (Number(selectedRowIndex) && selectedRowIndex > 0))
.forEach(row => {
let rowPos = row;

for (let cIndex = 0; cIndex < this.state.displayData.length; cIndex++) {
if (this.state.displayData[cIndex].dataIndex === row) {
rowPos = cIndex;
break;
}
}
}

selectedRowsData.data.push({ index: rowPos, dataIndex: row });
selectedRowsData.lookup[row] = true;
});
selectedRowsData.data.push({ index: rowPos, dataIndex: row });
selectedRowsData.lookup[row] = true;
});

// Single row selection customization
} else if (
Expand Down

0 comments on commit d1c979e

Please sign in to comment.