-
Notifications
You must be signed in to change notification settings - Fork 933
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
Feature/issue 871 (setCellHeaderProps) and Feature/issue 714 (setTableProps) #889
Conversation
I'm glad this is on your radar. Since discovering setCellProps and setRowsProps I've found them incredibly useful. They provide a lot of power and a nice reprieve from render functions. Some examples:
Render functions technically allow for the same thing, but I find them dreadful and they're way more complex than would seem. For example, to override a cell header, you really need to add in most of the functionality of TableHeadCell.js, and there's a lot going on in there. I don't think it's reasonable to assume that most devs will take the care to reproduce what's in there, leading to bugs in their code. Anyway, some time has passed since I put this in. setTableProps may be better off as "tableProps", as there's only 1 table. Additionally, if you decided you like this type of API, you may want to reconsider the searchProps idea of #808 (though that implementation is buggy - it's very close though). searchProps also makes a lot of customization trivial, and itsolves a lot of issues people brought up in #857 (comment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one needs an update with latest master
, and could we also add some tests for the new prop options?
@@ -1229,6 +1233,10 @@ class MUIDataTable extends React.Component { | |||
break; | |||
} | |||
|
|||
let tableProps = this.options.setTableProps ? this.options.setTableProps() : {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should be more defensive here. In case the function doesn't return an object, it will error out below. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, that's not how the existing setCellProps and setRowProps functions work. Trying out other return values in the console, it doesn't look like anything breaks with the spread operator, they just wouldn't be setting any fields if they had the function return a non-object (with the exception of a "string" type, where they'd set numerical fields on the component).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The others don't work this way because they aren't checking an object for a specific property. The new functions you added are checking to see if classNames
appears on the object, and this will error for non-objects, where the others won't, with the exception of strings.
@@ -12,18 +12,26 @@ const defaultBodyCellStyles = theme => ({ | |||
[theme.breakpoints.down('sm')]: { | |||
display: 'inline-block', | |||
fontSize: '16px', | |||
height: '24px', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we hold off on the stylistic changes here or put in another PR? I believe there were some modifications here since you opened this that might have solved some of the style issues, but also, if we keep them separate, then we can discuss them separately and then they won't hold up the other work here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're tied to the functionality a setTableProps method would add (ie, "dense table"). Without these changes, applying a dense table breaks stacked mode. There's actually bugs in the existing code, if you view the Customize Styling example you'll see one of them:
https://codesandbox.io/s/github/gregnb/mui-datatables/
The CSS solution I wound up with is simple. Initially I tried to be fancy, but it wasn't needed and didn't cover certain edge cases (basically a height parameter is needed for causes when cell values are empty or just a space).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so the problem is just that the PR is a two-for-one deal. In the future, I'd prefer to have them kept separate as this makes reviewing easier, but it's also much easier to trace back any future issues or regressions to a specific commit (since we squash merges) and enables us to rollback specific sets of functionality without losing others that work well, if need be.
@@ -89,7 +89,8 @@ class TableHeadCell extends React.Component { | |||
|
|||
render() { | |||
const { isSortTooltipOpen, isHintTooltipOpen } = this.state; | |||
const { children, classes, options, sortDirection, sort, hint, print } = this.props; | |||
const { children, classes, options, sortDirection, sort, hint, print, cellHeaderProps } = this.props; | |||
const { className, ...otherProps } = cellHeaderProps; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the other comment about checking for the className
property, as the dev will get an unhelpful error if they return the wrong type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow. Check that it's set to a string?
Understood about props vs render, I agree that custom render functions are a bad option when you want to replicate the functionality almost entirely, but with some slight changes. I think it would be a nice option to allow various parts of the table to be exported separately for just this kind of usage, but that's probably a ways away. I think render functions work best when the functionality being added is very custom and much different from what exists, and probably has a bunch of nested components and such. But use cases like those you mention are better served via adding props, so it's nice to have both. |
Hm, I don't see a big difference between Agreed about |
I can circle back a little later for tests. |
@patorjk If you want to take on |
Sure, I'll put something together, I'll loop back to it later this week or next. |
…o set-props # Conflicts: # README.md # src/MUIDataTable.js
…/activeIcon-for-search-not-reset-on-toggle * 'master' of github.com:gregnb/mui-datatables: 2.13.0 Prettify files Feature/issue 1036 fixed header (gregnb#1071) Update webpack dev server and related dependencies (gregnb#1069) Feature/issue 871 (setCellHeaderProps) and Feature/issue 714 (setTableProps) (gregnb#889) Feature/issue 937 array and custom update filter support (gregnb#1067) Bugfix/issue 1052 csv download issues (gregnb#1064) Hide toggle button when the row is not expandable (gregnb#1025) add test case to verify reset type (gregnb#1006) Update .gitignore and adding yarn.lock (gregnb#1004) Serverside sorting example (gregnb#986) No Pointer style cursor for table head when no hint or sorting (gregnb#910) Added disableToolbarSelect option (gregnb#874) Add table properties option (gregnb#670)
…eProps) (gregnb#889) * Added setTable props and setCellHeaderProps * Added height back in * Updated to properly work for classNames * Added stacked to initial state * minor adjustments * Fixed edge case of empty cell effecting the display * No getting around edge cases, a height is needed * Allow default in case using the component in isolation (like testing) * Add tests for new props options
#871 and #714
Added two new options:
They're modeled after the existing setCellProps and setRowProps. The dense table is really only available in Material v4, so the example only removes some padding in Material v3.
Quick view: https://codesandbox.io/s/github/patorjk/mui-datatables/tree/set-props