Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update pageSize value with javascript API #322

Closed
ghost opened this issue May 3, 2023 · 4 comments
Closed

update pageSize value with javascript API #322

ghost opened this issue May 3, 2023 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@ghost
Copy link

ghost commented May 3, 2023

I was messing with the Reactable.getState() function from the javascript API documentation and couldn't find a resource on updating the pageSize state property. ie. how to use the API to change the number of displayed rows (pageSize) from x to y.

I have read the rest of the documentation which updates other things like hidden columns, filters, etc... and came across the R function updateReactable() but neither seems to answer my question...

Thanks.

@ghost
Copy link
Author

ghost commented May 6, 2023

Figured it out. The answer, along with many other functionalities, is in .getInstance.

const newPageSize = 50;
Reactable.getInstance('table').setPageSize(newPageSize);

edit: trying to use a number from the virtualSelectInput value messes with the prev/next pagination actions - fixed this by using the parseFloat() function on the input.value (newPageSize).

@glin
Copy link
Owner

glin commented May 20, 2023

Yep, there's no support for updating the page size through the JavaScript API at the moment. You can definitely do it using getInstance().setPageSize(), but that's undocumented/internal so use at your own risk and double check that it still works on version upgrades.

This should be really simple to add to the JavaScript API though, and I could see it as a useful way to create your own pagination controls (along with prev/next page, go to page N).

@glin glin added the enhancement New feature or request label May 20, 2023
@ghost
Copy link
Author

ghost commented May 30, 2023

Ah, I have a few other uses from getInstance() that would be great to see supported eventually as well:

Case:
I want a table that can save filters to be applied later. It would save selected rows, which columns are being sorted, which columns are visible, and any other value that was being filtered with the filterMethod. I used the documented functions for all except these:

  • Functions:
    • Reactable.getInstance('tbl').setRowsSelected() I am using this to select rows from the saved filter
    • Reactable.getInstance('tbl').setSortBy() I am using this to apply the column sort from the saved filter

Thanks.

@glin glin added this to the v0.5.0 milestone Jun 12, 2023
@glin
Copy link
Owner

glin commented Jun 12, 2023

This is now in the development version:

setSortBy() is already on the roadmap (#316) and will probably be done soon-ish. setRowsSelected() would probably be another straightforward addition - can add that as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant