Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

enter image description here

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>

enter image description here

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:

enter image description here

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?

like image 737
Igal Avatar asked Oct 28 '25 04:10

Igal


1 Answers

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

hope this can help you

like image 129
ddann Avatar answered Oct 30 '25 11:10

ddann