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

Reset page number to 1 while making a client side sort

Open marceloverdijk opened this issue 1 year ago • 3 comments

Bootstraptable version(s) affected

1.21.0

Description

When making a sort, I would expect the table to reset to page number 1 automatically. But this is not the case.

Steps to reproduce:

  • https://live.bootstrap-table.com/code/marceloverdijk/12864
  • Go to page 2
  • Sot on any of the columns
  • Actual result: Table stays on page 2
  • Expected result: Reset page number to 1

The interesting part is that for server side sort the page number is reset. This was implemented by @UtechtDustin in 2019 with this PR: https://github.com/wenzhixin/bootstrap-table/pull/4414

Client vs Server side sorting does not seem to have consistent behaviour.

Example(s)

https://live.bootstrap-table.com/code/marceloverdijk/12864

Possible Solutions

No response

Additional Context

No response

marceloverdijk avatar Sep 18 '22 07:09 marceloverdijk

I don't would call it a bug, because its a matter of opinion what the right way is. But i agree, if i'm on page X and change the sort i can't know which data i will see after the sort (the larger the dataset is, the more likely it is that we have the problem).

So i would mark it as feature if you're fine @wenzhixin @djhvscf. What do you think ?

UtechtDustin avatar Sep 18 '22 10:09 UtechtDustin

Yes, I agree it is an opinion, so yes a feature request makes sense (although it already works like this for server side sorting via #4414)

marceloverdijk avatar Sep 18 '22 10:09 marceloverdijk

@UtechtDustin @wenzhixin @djhvscf I can try to provide a PR , do you think it's oke apply to reset page number when sorting by default (might be breaking for existing users) or to introduce an option for this?

marceloverdijk avatar Sep 20 '22 20:09 marceloverdijk

Both may make sense, but for client-side pagination, the initial design is to preserve page numbers when sorting. And no one else has asked questions for so long, so to maintain the previous behavior, I think it would be better to add a new option, for example: sortResetPage?

I looked at the stars feature on GitHub and found that it also preserves page numbers when sorting. https://github.com/stars/marceloverdijk/repositories?direction=desc&filter=all&page=2&sort=stars Change the sort option: image

wenzhixin avatar Oct 06 '22 15:10 wenzhixin

Hi @wenzhixin it absolutely makes sense to keep the current behaviour as default and introduce a sortResetPage option. I will update the existing PR or probably just create a new one.

Funny regarding the stars feature on Github preserving the page numbers when sorting. Other tables - like issue table - on Github reset the page number on sorting... ;-)

marceloverdijk avatar Oct 06 '22 20:10 marceloverdijk

@wenzhixin I've created a new PR: https://github.com/wenzhixin/bootstrap-table/pull/6445

marceloverdijk avatar Oct 07 '22 07:10 marceloverdijk