简体   繁体   中英

How to add an element to Material-UI TablePagination?

I'm using Material-UI Table with TablePagination in my project. This is how it appears:

在此处输入图片说明

Now I want the pagination to be aligned to left instead of right, and on the left I want to add another element, for example Button.

I was able to move the alignment to left by restyling the .spacer element. Here's my code:

<TableFooter>
      <TableRow>
        <TablePagination
          rowsPerPageOptions={[5, 10, 25]}
          colSpan={3}
          count={rows.length}
          rowsPerPage={rowsPerPage}
          page={page}
          SelectProps={{
            native: false,
          }}
          onChangePage={this.handleChangePage}
          onChangeRowsPerPage={this.handleChangeRowsPerPage}
          ActionsComponent={TablePaginationActions}
          classes={{spacer: classes.paginationSpacer}} >
        </TablePagination>
      </TableRow>
</TableFooter>

在此处输入图片说明

Now I'm trying to add another element. I tried to use action property:

action="<div>Some text</div>"

But that is not even showing. Tried to use

component="<td>Some text</td>"

Got the following error: Warning: validateDOMNesting(...): <<th>Some text</th>> cannot appear as a child of <tr>. Same thing with div.

Then I tried something like that:

...
<TableRow>
    <TablePagination
        ...all the props
    >
    </TablePagination>
    <td>Some text</td>
</TableRow>

The text appeared, but it completely scrambled my entire Table:

在此处输入图片说明

And <td> is about the only element that was even showing, since TableRow generates, well, <tr> element.

Any ideas how to insert an element in there?

<TableFooter>
    <TableRow>
        <TablePagination
            ...all the props
        >
        </TablePagination>
        <TableCell colSpan={1}>
            <p>Some text</p>
        </TableCell>
    </TableRow>
</TableFooter>

hope this can help you

You need to place the TablePagination outside of table all together.Look at the 3 example on the demos https://material-ui.com/components/tables/

<div>   
    <Table>
        ...
    </Table>
</div>

<TablePagination
    ...props
>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM