yiisoft / yii-dataview

Data widgets
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
38 stars 21 forks source link

Should ListView/GridView return to first page when sort changes #3

Closed Sammaye closed 2 months ago

Sammaye commented 10 years ago

I have noticed that I can be on page 3 of ListView but when I change the sort it remains on page 3. Logically you would expect it to return to page 1 since page 3 of a new sort is not very useful to the end user.

Should it be changed to go from page 1 when sort changes?

samdark commented 10 years ago

Probably yes.

philippfrenzel commented 10 years ago

Before changing anything, what scenarios for this are existing:

1) User is on page 4 with 20 records on the page, he want's to sort after a certain column, so he clicks it, now we have the following options:

So i think to cover both, you need a sort page and a sort total;)

Sammaye commented 10 years ago

Is there ever a time where the sort remaining on the same page is actually useful? I mean how do you know where you are in the dataset if the sort has now changed?

philippfrenzel commented 10 years ago

I hope someone from the core team can answer your question;)

samdark commented 10 years ago

Current page sorting could be useful if page has lots of results but such behavior logically conflicts with overall re-sorting.

samdark commented 10 years ago

@yiisoft/core-developers need more opinions.

LarryUllman commented 10 years ago

I think this is a definite "yes". If you change the sort criteria, it doesn't make sense NOT to update the display to start with page 1. I can't imagine a scenario in which I'm X pages into a view, decide to change the sort criteria, but would still want to be X pages in (under the different criteria).

koxu1996 commented 10 years ago

I agree with returning to the first page after change sorting.

rozzzly commented 10 years ago

That exceptional usecase seems too far fetch. I support @Sammaye's proposal.

samdark commented 10 years ago

Hmm... any thoughts about how to achieve it w/o Sort doing Pagination job?

samdark commented 10 years ago

Changed milestone to 2.1 since it's not critical for 2.0 release.

Sammaye commented 10 years ago

Cant you just amend the ListView/GridView sorter methods to include custom urls for the sort functions which exclude the page var as defined in the pagination class?

So just add Url handling specifically for the view, i.e. listview within render sorter of: https://github.com/yiisoft/yii2/blob/master/framework/widgets/BaseListView.php

It seems like either way the sorter needs to be aware of the pagination in the case of these widgets and customise its links when uysed in thisn context.

IvoPereira commented 9 years ago

+1. This would come in handy.

Faryshta commented 9 years ago

@Sammaye you can extend the \yii\data\Sort class and edit this method. https://github.com/yiisoft/yii2/blob/master/framework/data/Sort.php#L335

what you want would be as simple as adding this line on line 340

unset($params['page']) assuming that your page attribute is 'page'

dynasource commented 8 years ago

staying on the same page (depth) is not really logical, as this is related to another sort criterium. This is room for improvement. @Sammaye, @Faryshta , do you have ideas for a PR?

Sammaye commented 8 years ago

It's been so long I cannot even remember the file that deals with this, I think it is Pagination.php or something

thiagovidal commented 6 years ago

Any news on this?

samdark commented 6 years ago

No.

nutfergie commented 5 years ago
        $(document).on('pjax:success', function() {
             $('#grid_id th a').attr('href', function(i,data){
                 return  data.replace( /&page=[0-9]/gi, '' );        
      });

I solve it via jquery

vjik commented 2 months ago

Currently, we can use GridView method keepPageOnSort() to configure it. By default page don't keep on sort changing.