Reputation: 53
i have some questions :) i try to put an Avatar tag in every row in my table and edit Button, and its take the edit button to both. How can I move an action to the right side of the table? How do I undo the title of "Actions" at the top of the table? And what exactly "PROPS" should I pass if I use TS in the following example:
<MaterialTable
icons={tableIcons}
columns={this.state.columns}
data={this.state.data}
title='Users Management'
actions={[
{
icon: 'edit',
tooltip: 'Edit User',
onClick: (event) => { alert('Edit!!'); },
},
{
icon: 'avatar',
tooltip: 'Avatar User',
onClick: (event) => { alert("You want to delete "); }
}
]}
components={{
Action: **props** => (
<Button
onClick={(event: any) => props.action.onClick}>
EDIT
</Button>
),
}}
/>
Upvotes: 4
Views: 2529
Reputation: 20088
We can use component to property to set action in the following way.
<MaterialTable
localization={{header: { actions: '' }}} // rename action column header
options={{
actionsColumnIndex: 3, // move action column at what index we need (In mycase right side)
exportButton: false,
filtering: false,
paging: false,
search: false,
}}
columns={[
{ field: 'use', title: 'Use' },
{ field: 'shortName', title: 'Short Name' },
{ field: 'Id', title: 'ID' },
]}
data={[
{ Id: 63, shortName: 'Aliquet', use: 'Eget' },
{ Id: 34, shortName: 'Praesent', use: 'Nibh' },
{ Id: 63, shortName: 'Eget', use: 'Tristique' },
]}
actions={[
{
// icon: () => <DeleteOutline/>,
onClick: (event, rowData) => {},
tooltip: 'Clear',
}
]}
components={{
Action: props => <Button onClick={event => props.action.onClick(event, props.data)}>Clear</Button>, // Customized action button added.
Toolbar: () => <span></span>, // customize toolbar (In mycase I'm removed toolbar)
}}
title={''}
/>
Upvotes: 0
Reputation: 8774
So lets split this question into parts:
How do I undo the title of "Actions" at the top of the table? You can simply override the localization={{header.actions: 'Test'}}
prop to change the action column title to change it e.g. to Test. You can also add a white space to hide it.
How can I move an action to the right side of the table? You can override options={{actionsColumnIndex: 1}}
to e.g. move it to the second position or set it to -1 to move it to the end of all columns.
its take the edit button to both. Since you do not provide custom elements, it renders a text. You have to import icons={tableIcons}
as written in the readme. To show an avatar icon, simply add avatars object to your tableIcons
object.
To know which props to pass, look at this docs page.
Upvotes: 1