CrowdStrike / ember-headless-table

https://ember-headless-table.pages.dev
MIT License
23 stars 7 forks source link

Pagination handling example #241

Closed Polve closed 9 months ago

Polve commented 9 months ago

In the class list I found something related to pagination but I can't find any example using it so I'm unable to understand how to use it

NullVoxPopuli commented 9 months ago

Pagination is handled externally: You'd do something like this (where you make the components, and YourTable wraps the headless table)

<Data as |d|>
  <YourTable @data={{d.records}} />
  <Pagination @meta={{d.meta}} @onNext={{d.nextPage}} />
</Data>

records would be tracked, no when the pagination component tells the data component to update, the table component updates because of auto tracking

The pagination interface in this repo was accidentally left in, and isn't actually used, afaik

Polve commented 9 months ago

Thanks

in the example above, how can I tell the table that I changed the @data (without triggering a new route)?

NullVoxPopuli commented 9 months ago

Why don't you want to trigger a route transition? Generally folks want table state serialized to the URL

Polve commented 9 months ago

Because I have several tables inside my page and I want to be able to paginate each one indipendently

NullVoxPopuli commented 9 months ago

If you move all data loading for each table into component-land instead of the route, your goal is very doable

Polve commented 9 months ago

yes that's my goal, but how do I trigger a table redraw after pressing the pagination buttons?

NullVoxPopuli commented 9 months ago

In the example, if records is @tracked , and your function for handling page changes updates records, there is nothing for you to do. The framework handles the update 🎉

I can share a real/runnable example later if you're still stuck

Polve commented 9 months ago

Everything works as expected, thanks! I close this since I overlooked #163 that was already on topic