Skip to content

Commit

Permalink
(feature) Allow custom hide columns action (#833)
Browse files Browse the repository at this point in the history
* (feature) send columns data and onColumnsChanged callback to Toolbar custom Actions

* passing columns and onColumnsChanged down to Action component

* chore MTableToolbar: Check if onColumnsChanged is defined before calling it

---------

Co-authored-by: Emiliano Morghen <emiliano.morghen@sparkfabrik.com>
Co-authored-by: Domino987 <domino051@gmail.com>
  • Loading branch information
3 people committed Apr 19, 2024
1 parent f5229e8 commit b489dc9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/MTableAction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ MTableAction.defaultProps = {

MTableAction.propTypes = {
action: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired,
columns: PropTypes.array.isRequired,
data: PropTypes.oneOfType([
PropTypes.object,
PropTypes.arrayOf(PropTypes.object)
]),
disabled: PropTypes.bool,
onColumnsChanged: PropTypes.func.isRequired,
size: PropTypes.string
};

Expand Down
6 changes: 6 additions & 0 deletions src/components/MTableActions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import PropTypes from 'prop-types';

function MTableActions({
actions,
columns,
components,
data,
onColumnsChanged,
size,
disabled,
forwardedRef
Expand All @@ -18,8 +20,10 @@ function MTableActions({
<components.Action
action={action}
key={'action-' + index}
columns={columns}
data={data}
size={size}
onColumnsChanged={onColumnsChanged}
disabled={disabled}
/>
))}
Expand All @@ -33,13 +37,15 @@ MTableActions.defaultProps = {
};

MTableActions.propTypes = {
columns: PropTypes.array.isRequired,
components: PropTypes.object.isRequired,
actions: PropTypes.array.isRequired,
data: PropTypes.oneOfType([
PropTypes.object,
PropTypes.arrayOf(PropTypes.object)
]),
disabled: PropTypes.bool,
onColumnsChanged: PropTypes.func.isRequired,
size: PropTypes.string,
forwardedRef: PropTypes.element
};
Expand Down
4 changes: 4 additions & 0 deletions src/components/MTableToolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ export function MTableToolbar(props) {
props.actions &&
props.actions.filter((a) => a.position === diplayedActions)
}
columns={props.columns}
onColumnsChanged={(col, hidden) =>
props.onColumnsChanged && props.onColumnsChanged(col, hidden)
}
data={isSelectionActive ? selectedRows : undefined}
components={props.components}
/>
Expand Down

0 comments on commit b489dc9

Please sign in to comment.