Skip to content

Commit

Permalink
fix for resizable tables
Browse files Browse the repository at this point in the history
  • Loading branch information
patorjk committed Jul 24, 2020
1 parent 92d0dd7 commit 021a617
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
24 changes: 21 additions & 3 deletions examples/resizable-columns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import MUIDataTable from "../../src/";

import FormControl from '@material-ui/core/FormControl';
import TextField from '@material-ui/core/TextField';
import Switch from '@material-ui/core/Switch';
import FormGroup from '@material-ui/core/FormGroup';
import FormControlLabel from '@material-ui/core/FormControlLabel';

function Example(props) {

const [marginLeft, setMarginLeft] = useState(10);
const [selectableRows, setSelectableRows] = useState("multiple");

const [counter, setCounter] = useState(1);
const incrCount = () => { // We update an arbitrary value here to test table resizing on state updates
Expand Down Expand Up @@ -78,16 +82,30 @@ function Example(props) {
filter: true,
filterType: 'dropdown',
resizableColumns: true,
selectableRows: selectableRows,
draggableColumns: {
enabled: true,
}
};

return (
<>
<FormControl>
<TextField label="Left Margin" type="number" value={marginLeft} onChange={(e) => setMarginLeft(e.target.value)} />
</FormControl>
<FormGroup row>
<FormControl>
<TextField label="Left Margin" type="number" value={marginLeft} onChange={(e) => setMarginLeft(e.target.value)} />
</FormControl>
<FormControlLabel
control={
<Switch
checked={selectableRows === "multiple"}
onChange={(e) => setSelectableRows(event.target.checked ? "multiple" : "none")}
value="true"
color="primary"
/>
}
label="Selectable Rows"
/>
</FormGroup>
<div style={{marginLeft: marginLeft + 'px'}}>
<MUIDataTable title={"ACME Employee list" + " [" + counter + "]"} data={data} columns={columns} options={options} />
<div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/TableResize.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ class TableResize extends React.Component {
};

const isLastColumn = (id, finalCells) => {
return id === finalCells.length - 2;
let len = (selectableRows === 'none') ? 1 : 2;
return id === finalCells.length - len;
};

if (isFirstColumn(selectableRows, idNumber) && isLastColumn(idNumber, finalCells)) {
Expand Down
1 change: 0 additions & 1 deletion test/MUIDataTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ describe('<MUIDataTable />', function() {
viewColumns: true,
sortCompare: null,
sortThirdClickReset: false,

},
{
display: 'true',
Expand Down

0 comments on commit 021a617

Please sign in to comment.