Skip to content

Commit

Permalink
Merge pull request #1332 from gregnb/v3_0_1
Browse files Browse the repository at this point in the history
version 3.0.1
  • Loading branch information
patorjk authored Jun 15, 2020
2 parents 8158e23 + c13e7a9 commit 88227f3
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 218 deletions.
38 changes: 0 additions & 38 deletions CHANGELOG.md

This file was deleted.

14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ If your project doesn't already use them, you need to install `@material-ui/core

## Demo

[![Edit react-to-print](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/gregnb/mui-datatables)
[![Edit react-to-print](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/muidatatables-custom-toolbar-rvmcj?file=/index.js)

Browse live demos of all examples in this repo in [here](https://codesandbox.io/s/github/gregnb/mui-datatables)!

## Usage

Expand Down Expand Up @@ -154,15 +156,15 @@ The component accepts the following props:
|**`caseSensitive `**|boolean|false|Enable/disable case sensitivity for search.
|**`confirmFilters`**|boolean|false|Works in conjunction with the **customFilterDialogFooter** option and makes it so filters have to be confirmed before being applied to the table. When this option is true, the customFilterDialogFooter callback will receive an applyFilters function which, when called, will apply the filters to the table. [Example](https://github.com/gregnb/mui-datatables/blob/master/examples/serverside-filters/index.js)
|**`count`**|number||User provided override for total number of rows.
|**`customFilterDialogFooter `**|function||Add a custom footer to the filter dialog. `customFilterDialogFooter(curentFilterList: array, applyFilters: function) => React Component`
|**`customFooter`**|function||Render a custom table footer. `function(count, page, rowsPerPage, changeRowsPerPage, changePage, `[`textLabels: object`](https://github.com/gregnb/mui-datatables/blob/master/src/textLabels.js)`) => string`|` React Component` [Example](https://github.com/gregnb/mui-datatables/blob/master/examples/customize-footer/index.js)
|**`customRowRender `**|function||Override default row rendering with custom function. `customRowRender(data, dataIndex, rowIndex) => React Component`
|**`customSearch `**|function||Override default search with custom function. `customSearch(searchQuery: string, currentRow: array, columns: array) => boolean`
|**`customSearchRender `**|function||Render a custom table search. `customSearchRender(searchText: string, handleSearch, hideSearch, options) => React Component`
|**`customSort`**|function||Override default sorting with custom function. `function(data: array, colIndex: number, order: string) => array`
|**`customTableBodyFooterRender`**|function||Render a footer under the table body but above the table's standard footer. This is useful for creating footers for individual columns. [Example](https://github.com/gregnb/mui-datatables/blob/master/examples/customize-footer/index.js)
|**`customToolbar`**|function||Render a custom toolbar
|**`customToolbarSelect`**|function||Render a custom selected rows toolbar. `function(selectedRows, displayData, setSelectedRows) => void`
|**`customRowRender `**|function||Override default row rendering with custom function. `customRowRender(data, dataIndex, rowIndex) => React Component`
|**`customSearch `**|function||Override default search with custom function. `customSearch(searchQuery: string, currentRow: array, columns: array) => boolean`
|**`customSearchRender `**|function||Render a custom table search. `customSearchRender(searchText: string, handleSearch, hideSearch, options) => React Component`
|**`customFilterDialogFooter `**|function||Add a custom footer to the filter dialog. `customFilterDialogFooter(curentFilterList: array, applyFilters: function) => React Component`
|**`download`**|boolean|true|Show/hide download icon from toolbar
|**`downloadOptions`**|object|`{filename: 'tableDownload.csv', separator: ','}`|Options to change the output of the CSV file: `filename`: string, `separator`: string, `filterOptions`: object(`useDisplayedColumnsOnly`: boolean, `useDisplayedRowsOnly`: boolean)
|**`elevation`**|number|4|Shadow depth applied to Paper component.
Expand Down Expand Up @@ -201,8 +203,8 @@ The component accepts the following props:
|**`renderExpandableRow`**|function||Render expandable row. `function(rowData, rowMeta) => React Component` [Example](https://github.com/gregnb/mui-datatables/blob/master/examples/expandable-rows/index.js)
|**`resizableColumns`**|boolean|false|Enable/disable resizable columns.
|**`responsive`**|string|'stacked'|Enable/disable responsive table views. Options: <p><ul><li>"vertical" (default value): In smaller views the table cells will collapse such that the heading is to the left of the cell value.</li><li>"standard": Table will stay in the standard mode but make small changes to better fit the allocated space.<li>"simple": On very small devices the table rows will collapse into simple display.</li></ul></p>[Example](https://github.com/gregnb/mui-datatables/blob/master/examples/simple/index.js)
|**`rowsExpanded`**|array||User provided expanded rows.
|**`rowHover`**|boolean|true|Enable/disable hover style over rows.
|**`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.
Expand Down
135 changes: 80 additions & 55 deletions examples/resizable-columns/index.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,95 @@
import React from "react";
import React, { useState } from "react";
import ReactDOM from "react-dom";
import MUIDataTable from "../../src/";

class Example extends React.Component {
import FormControl from '@material-ui/core/FormControl';
import TextField from '@material-ui/core/TextField';

constructor(props) {
super(props);
function Example(props) {

this.state = { counter: 1 };
}
const [marginLeft, setMarginLeft] = useState(10);

// We update an arbitrary value here to test table resizing on state updates
update = () => {
let { counter } = this.state;
counter += 1;

this.setState({ counter });
const [counter, setCounter] = useState(1);
const incrCount = () => { // We update an arbitrary value here to test table resizing on state updates
setCounter(counter + 1);
};

render() {
const { counter } = this.state;

const columns = [
{
name: "Counter",
options: {
empty: true,
customBodyRender: value => <button onClick={this.update}>+</button>
}
},
{
name: "Name",
options: {
sort: false,
hint: "?"
}
},
{
name: "Title",
options: {
hint: "?"
const columns = [
{
name: "Counter",
options: {
empty: true,
customBodyRender: value => <button onClick={incrCount}>+</button>
}
},
{
name: "Name",
options: {
sort: false,
hint: "?",
setCellProps: () => ({style: {whiteSpace:'nowrap'}})
}
},
{
name: "Business Title",
options: {
hint: "?",
customBodyRender: (val) => {
let parentStyle = {
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
boxSizing: 'border-box',
display: 'block',
width: '100%',
};
let cellStyle = {
boxSizing: 'border-box',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
};
return (
<div style={{position:'relative', height: '20px'}}>
<div style={parentStyle}>
<div style={cellStyle}>
{val}
</div>
</div>
</div>
);
}
},
"Location"
];
}
},
"Location"
];

const data = [
["Gabby George", "Business Analyst", "Minneapolis"],
["Aiden Lloyd", "Business Consultant", "Dallas"],
["Jaden Collins", "Attorney", "Santa Ana"],
["Franky Rees", "Business Analyst", "St. Petersburg"],
["Aaren Rose", null, "Toledo"]
];
const data = [
["Gabby George ", "Business Analyst", "Minneapolis"],
["Aiden Lloyd", "Business Consultant at Tony's Burger Palace and CEO of Johnny's Blueberry Sundaes", "Dallas"],
["Jaden Collins", "Attorney", "Santa Ana"],
["Franky Rees", "Business Analyst", "St. Petersburg"],
["Aaren Rose", null, "Toledo"]
];

const options = {
filter: true,
filterType: 'dropdown',
resizableColumns: true,
};

const options = {
filter: true,
filterType: 'dropdown',
resizableColumns: true
};

return (
<MUIDataTable title={"ACME Employee list" + " [" + counter + "]"} data={data} columns={columns} options={options} />
);

}
return (
<>
<FormControl>
<TextField label="Left Margin" type="number" value={marginLeft} onChange={(e) => setMarginLeft(e.target.value)} />
</FormControl>
<div style={{marginLeft: marginLeft + 'px'}}>
<MUIDataTable title={"ACME Employee list" + " [" + counter + "]"} data={data} columns={columns} options={options} />
</div>
</>
);
}

export default Example;
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mui-datatables",
"version": "3.0.0-beta.2",
"version": "3.0.1",
"description": "Datatables for React using Material-UI",
"main": "dist/index.js",
"files": [
Expand Down
12 changes: 8 additions & 4 deletions src/MUIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class MUIDataTable extends React.Component {
tableBodyHeight: PropTypes.string,
tableBodyMaxHeight: PropTypes.string,
renderExpandableRow: PropTypes.func,
resizableColumns: PropTypes.bool,
resizableColumns: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
responsive: PropTypes.oneOf(['standard', 'vertical', 'simple']),
rowHover: PropTypes.bool,
rowsExpanded: PropTypes.array,
Expand Down Expand Up @@ -321,7 +321,10 @@ class MUIDataTable extends React.Component {
this.setState({ page: 0 });
}

if (this.options.resizableColumns) {
if (
this.options.resizableColumns === true ||
(this.options.resizableColumns && this.options.resizableColumns.enabled)
) {
this.setHeadResizeable(this.headCellRefs, this.tableRef);
this.updateDividers();
}
Expand Down Expand Up @@ -894,7 +897,7 @@ class MUIDataTable extends React.Component {
const filterType = column.filterType || options.filterType;
if (filterVal.length || filterType === 'custom') {
if (column.filterOptions && column.filterOptions.logic) {
if (column.filterOptions.logic(columnValue, filterVal)) isFiltered = true;
if (column.filterOptions.logic(columnValue, filterVal, row)) isFiltered = true;
} else if (filterType === 'textField' && !this.hasSearchText(columnVal, filterVal, caseSensitive)) {
isFiltered = true;
} else if (
Expand Down Expand Up @@ -1747,7 +1750,8 @@ class MUIDataTable extends React.Component {
columnNames={columnNames}
/>
<div style={{ position: 'relative', ...tableHeightVal }} className={responsiveClass}>
{this.options.resizableColumns && (
{(this.options.resizableColumns === true ||
(this.options.resizableColumns && this.options.resizableColumns.enabled)) && (
<TableResizeComponent
key={rowCount}
updateDividers={fn => (this.updateDividers = fn)}
Expand Down
Loading

0 comments on commit 88227f3

Please sign in to comment.