Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to pass tableId as a prop #1472

Merged
merged 1 commit into from
Aug 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/MUIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class MUIDataTable extends React.Component {
selectableRowsHideCheckboxes: PropTypes.bool,
selectableRowsOnClick: PropTypes.bool,
serverSide: PropTypes.bool,
tableId: PropTypes.string,
tableBodyHeight: PropTypes.string,
tableBodyMaxHeight: PropTypes.string,
renderExpandableRow: PropTypes.func,
Expand Down Expand Up @@ -268,7 +269,6 @@ class MUIDataTable extends React.Component {

constructor(props) {
super(props);
this.tableId = (Math.random() + '').replace(/\./, '');
this.tableRef = React.createRef();
this.tableContent = React.createRef();
this.draggableHeadCellRefs = {};
Expand Down Expand Up @@ -358,6 +358,11 @@ class MUIDataTable extends React.Component {
props.options.selectToolbarPlacement = STP.NONE;
}

// provide default tableId when draggableColumns is enabled and no tableId has been passed as prop
if (props.options.draggableColumns.enabled === true && !props.options.tableId) {
props.options.tableId = (Math.random() + '').replace(/\./, '');
}

this.options = assignwith(options, props.options, (objValue, srcValue, key) => {
// Merge any default options that are objects, as they will be overwritten otherwise
if (key === 'textLabels' || key === 'downloadOptions') return merge(objValue, srcValue);
Expand Down Expand Up @@ -1956,7 +1961,7 @@ class MUIDataTable extends React.Component {
updateDividers={fn => (this.updateDividers = fn)}
setResizeable={fn => (this.setHeadResizeable = fn)}
options={this.props.options}
tableId={this.tableId}
tableId={this.options.tableId}
/>
)}
<DndProvider backend={HTML5Backend} {...dndProps}>
Expand Down Expand Up @@ -1987,7 +1992,7 @@ class MUIDataTable extends React.Component {
updateColumnOrder={this.updateColumnOrder}
draggableHeadCellRefs={this.draggableHeadCellRefs}
tableRef={this.getTableContentRef}
tableId={this.tableId}
tableId={this.options.tableId}
timers={this.timers}
components={this.props.components}
/>
Expand All @@ -2006,7 +2011,7 @@ class MUIDataTable extends React.Component {
columnOrder={columnOrder}
filterList={filterList}
components={this.props.components}
tableId={this.tableId}
tableId={this.options.tableId}
/>
{this.options.customTableBodyFooterRender
? this.options.customTableBodyFooterRender({
Expand Down