Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #21 from patorjk/state_fixes
Browse files Browse the repository at this point in the history
state fixes
  • Loading branch information
patorjk committed Sep 28, 2019
2 parents 892c813 + 9bd7676 commit d9115a1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 42 deletions.
69 changes: 34 additions & 35 deletions examples/customize-styling/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,39 @@ class Example extends React.Component {
super(props);
this.state = {
denseTable: false,
stacked: true
stacked: true,
data: [
["Gabby George", "Business Analyst", "Minneapolis", 30, 100000],
["Aiden Lloyd", "Business Consultant", "Dallas", 55, 200000],
["Jaden Collins", "Attorney", "Santa Ana", 27, 500000],
["Franky Rees", "Business Analyst", "St. Petersburg", 22, 50000],
["Aaren Rose", "Business Consultant", "Toledo", 28, 75000],
["Blake Duncan", "Business Management Analyst", "San Diego", 65, 94000],
["Frankie Parry", "Agency Legal Counsel", "Jacksonville", 71, 210000],
["Lane Wilson", "Commercial Specialist", "Omaha", 19, 65000],
["Robin Duncan", "Business Analyst", "Los Angeles", 20, 77000],
["Mel Brooks", "Business Consultant", "Oklahoma City", 37, 135000],
["Harper White", "Attorney", "Pittsburgh", 52, 420000],
["Kris Humphrey", "Agency Legal Counsel", "Laredo", 30, 150000],
["Frankie Long", "Industrial Analyst", "Austin", 31, 170000],
["Brynn Robbins", "Business Analyst", "Norfolk", 22, 90000],
["Justice Mann", "Business Consultant", "Chicago", 24, 133000],
["Addison Navarro", "Business Management Analyst", "New York", 50, 295000],
["Jesse Welch", "Agency Legal Counsel", "Seattle", 28, 200000],
["Eli Mejia", "Commercial Specialist", "Long Beach", 65, 400000],
["Gene Leblanc", "Industrial Analyst", "Hartford", 34, 110000],
["Danny Leon", "Computer Scientist", "Newark", 60, 220000],
["Lane Lee", "Corporate Counselor", "Cincinnati", 52, 180000],
["Jesse Hall", "Business Analyst", "Baltimore", 44, 99000],
["Danni Hudson", "Agency Legal Counsel", "Tampa", 37, 90000],
["Terry Macdonald", "Commercial Specialist", "Miami", 39, 140000],
["Justice Mccarthy", "Attorney", "Tucson", 26, 330000],
["Silver Carey", "Computer Scientist", "Memphis", 47, 250000],
["Franky Miles", "Industrial Analyst", "Buffalo", 49, 190000],
["Glen Nixon", "Corporate Counselor", "Arlington", 44, 80000],
["Gabby Strickland", "Business Process Consultant", "Scottsdale", 26, 45000],
["Mason Ray", "Computer Scientist", "San Francisco", 39, 142000]
],
};
}

Expand Down Expand Up @@ -112,39 +144,6 @@ class Example extends React.Component {
}
];

const data = [
["Gabby George", "Business Analyst", "Minneapolis", 30, 100000],
["Aiden Lloyd", "Business Consultant", "Dallas", 55, 200000],
["Jaden Collins", "Attorney", "Santa Ana", 27, 500000],
["Franky Rees", "Business Analyst", "St. Petersburg", 22, 50000],
["Aaren Rose", "Business Consultant", "Toledo", 28, 75000],
["Blake Duncan", "Business Management Analyst", "San Diego", 65, 94000],
["Frankie Parry", "Agency Legal Counsel", "Jacksonville", 71, 210000],
["Lane Wilson", "Commercial Specialist", "Omaha", 19, 65000],
["Robin Duncan", "Business Analyst", "Los Angeles", 20, 77000],
["Mel Brooks", "Business Consultant", "Oklahoma City", 37, 135000],
["Harper White", "Attorney", "Pittsburgh", 52, 420000],
["Kris Humphrey", "Agency Legal Counsel", "Laredo", 30, 150000],
["Frankie Long", "Industrial Analyst", "Austin", 31, 170000],
["Brynn Robbins", "Business Analyst", "Norfolk", 22, 90000],
["Justice Mann", "Business Consultant", "Chicago", 24, 133000],
["Addison Navarro", "Business Management Analyst", "New York", 50, 295000],
["Jesse Welch", "Agency Legal Counsel", "Seattle", 28, 200000],
["Eli Mejia", "Commercial Specialist", "Long Beach", 65, 400000],
["Gene Leblanc", "Industrial Analyst", "Hartford", 34, 110000],
["Danny Leon", "Computer Scientist", "Newark", 60, 220000],
["Lane Lee", "Corporate Counselor", "Cincinnati", 52, 180000],
["Jesse Hall", "Business Analyst", "Baltimore", 44, 99000],
["Danni Hudson", "Agency Legal Counsel", "Tampa", 37, 90000],
["Terry Macdonald", "Commercial Specialist", "Miami", 39, 140000],
["Justice Mccarthy", "Attorney", "Tucson", 26, 330000],
["Silver Carey", "Computer Scientist", "Memphis", 47, 250000],
["Franky Miles", "Industrial Analyst", "Buffalo", 49, 190000],
["Glen Nixon", "Corporate Counselor", "Arlington", 44, 80000],
["Gabby Strickland", "Business Process Consultant", "Scottsdale", 26, 45000],
["Mason Ray", "Computer Scientist", "San Francisco", 39, 142000]
];

const options = {
filter: true,
filterType: 'dropdown',
Expand Down Expand Up @@ -191,7 +190,7 @@ class Example extends React.Component {
label="Stacked Table"
/>
</FormGroup>
<MUIDataTable title={"ACME Employee list"} data={data} columns={columns} options={options}/>
<MUIDataTable title={"ACME Employee list"} data={this.state.data} columns={columns} options={options}/>
</MuiThemeProvider>
);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mui-dt",
"version": "0.8.2",
"version": "0.8.3",
"description": "Datatables for React using Material-UI",
"main": "dist/index.js",
"files": [
Expand Down
19 changes: 13 additions & 6 deletions src/MUIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,15 @@ class MUIDataTable extends React.Component {
}

componentDidUpdate(prevProps) {
if (this.props.data !== prevProps.data || this.props.columns !== prevProps.columns) {
if (this.props.data !== prevProps.data || this.props.columns !== prevProps.columns || this.props.options !== prevProps.options) {
this.updateOptions(this.options, this.props);
this.setTableData(this.props, TABLE_LOAD.INITIAL, () => {

var didDataUpdate = this.props.data !== prevProps.data;
if ( this.props.data && prevProps.data ) {
didDataUpdate = didDataUpdate && (this.props.data.length === prevProps.data.length);
}

this.setTableData(this.props, TABLE_LOAD.INITIAL, didDataUpdate, () => {
this.setTableAction('propsUpdate');
});
}
Expand Down Expand Up @@ -268,7 +274,7 @@ class MUIDataTable extends React.Component {
initializeTable(props) {
this.mergeDefaultOptions(props);
this.setTableOptions();
this.setTableData(props, TABLE_LOAD.INITIAL, () => {
this.setTableData(props, TABLE_LOAD.INITIAL, true, () => {
this.setTableInit('tableInitialized');
});
}
Expand Down Expand Up @@ -455,7 +461,7 @@ class MUIDataTable extends React.Component {
});
};

setTableData(props, status, callback = () => {}) {
setTableData(props, status, dataUpdated, callback = () => {}) {
let tableData = [];
let { columns, filterData, filterList } = this.buildColumns(props.columns, this.state.columns);
let sortIndex = null;
Expand Down Expand Up @@ -587,7 +593,7 @@ class MUIDataTable extends React.Component {
console.error(
'Multiple values provided for selectableRows, but selectableRows set to "single". Either supply only a single value or use "multiple".',
);
} else {
} else if (typeof this.options.rowsSelected === 'undefined' && dataUpdated === false) {
if (this.state.selectedRows) {
selectedRowsData = Object.assign({}, this.state.selectedRows);
}
Expand All @@ -607,7 +613,7 @@ class MUIDataTable extends React.Component {
expandedRowsData.data.push({ index: rowPos, dataIndex: row });
expandedRowsData.lookup[row] = true;
});
} else if (this.state.expandedRows) {
} else if (typeof this.options.rowsExpanded === 'undefined' && dataUpdated === false && this.state.expandedRows) {
expandedRowsData = Object.assign({}, this.state.expandedRows);
}
}
Expand Down Expand Up @@ -1032,6 +1038,7 @@ class MUIDataTable extends React.Component {
},
},
TABLE_LOAD.UPDATE,
true,
() => {
this.setTableAction('rowDelete');
},
Expand Down

0 comments on commit d9115a1

Please sign in to comment.