material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Conditional Paging Options

Open orhanhub opened this issue 5 years ago • 1 comments

Cannot Conditionally Select Options

  • Demo of the Issue

  • I want to conditionally set paging option based on the data length, but it is not working for me.

  • Details

Say I fetch a remote data. The data length is say an array with 3 elements. I don't want paging option. Say I fetch a remote data for another user, the data length is say an array with 150 elements, I want paging options with default pagingSize 50 and pageSizeOptions of 50, 100, 200.

When I use ternary conditionals, immediately executed functions, call whatever, the conditional format defaults the paging size to 5 (Five). But the dropdown has (50, 100, 200). On the console I get the following error:

Material-UI: You have provided an out-of-range value `5` for the select component. Consider providing a value that matches one of the available options or ''. The available values are `50`, `100`, `200`.

orhanhub avatar Mar 19 '21 01:03 orhanhub

The answer is: I was just passing

pageSize:50,
pageSizeOptions: [50,100,200]
}```

but I did not pass `paging: true` with it, 

so the better option was:

``` const options = {
paging: fetchedData.length > 49,
pageSize: 50,
pageSizeOptions: [50, 100, 200]
}

orhanhub avatar Mar 19 '21 01:03 orhanhub