Export to GitHub

primefaces - issue #3887

DataTable default sort not applied after ajax update


Posted on Apr 6, 2012 by Quick Kangaroo

What is the PrimeFaces forum discussion URL? http://forum.primefaces.org/viewtopic.php?f=3&t=20107&p=62616#p62616

What steps will reproduce the problem? 1. Create a datatable with an AJAX listener on the sort event and some backing bean properties for soryBy and SortType.

  1. Use the AJAX listener to store the sort values in the backing bean (in the properties that are used above).

  2. Refresh the datatable with an AJAX call from another component on the page. Something like <p:commandButton update="datatable">

  3. Notice that the sort spec has reverted to the order that the objects are defined in. It is no longer sorting based on the column you selected and it doesn't seem to be using the default sort values.

What is the PrimeFaces version? 3.2

What is the expected output? What do you see instead? I'd like the refreshed table to apply the sort spec that is defined in its tag.

Which JSF implementation with version are you using?(Mojarra or MyFaces) Mojarra 2.1.7

What is the version of your JSF implementation? 2.1.7

Which component libraries are you using in addition to PrimeFaces? None

Which application server or servlet container are you using? Tomcat 7.0.22

Backing Bean: private String caseListSortOrder = "DESCENDING";

public String getCaseListSortOrder() { return caseListSortOrder; }
public void setCaseListSortOrder(String caseListSortType) { this.caseListSortOrder = caseListSortType; }

private Column caseListSortBy;

public Column getCaseListSortBy() {return caseListSortBy;}
public void setCaseListSortBy(Column caseListSortBy) {this.caseListSortBy = caseListSortBy;}

public void caseListSortListner(SortEvent sortEvent){
    this.caseListSortBy = sortEvent.getSortColumn();
    if (sortEvent.isAscending()){
        this.caseListSortOrder = &quot;ASCENDING&quot;;
    }else{
         this.caseListSortOrder = &quot;DESCENDING&quot;;       

}

DataTable:

<p:dataTable id="case-table" widgetVar="caseTableWidget" value="#{queueBackingBean.cases}" var="aCase"
styleClass="case-table" selectionMode="single" selection="#{queueBackingBean.viewingCase}" rowKey="#{aCase.caseNumber}" scrollable="true" scrollHeight="500" sortBy="#{queueBackingBean.caseListSortBy}" sortOrder="#{queueBackingBean.caseListSortOrder}" >

                &lt;p:ajax event=&quot;sort&quot;
                        listener=&quot;#{queueBackingBean.caseListSortListner}&quot;/&gt;

Comment #1

Posted on Apr 6, 2012 by Quick Kangaroo

I just found issue 2198. This appears to be a duplicate. HOWEVER, based on the comments in that bug it looks like there's no way to have the table maintain it's sort spec. Can I please change this issue report to a feature request. I would like to have someone add a property that we can use to apply a sort at each refresh (not just initial load).

Comment #2

Posted on May 2, 2012 by Grumpy Monkey

i have the same problem

Comment #3

Posted on May 4, 2012 by Helpful Rhino

The same problem, any sort in p:datatable by default destroyed after ANY ajax update of the table or page.

Comment #4

Posted on Jul 9, 2012 by Helpful Hippo

The main problem with sorting is that DataTable shows the last user's sorting in table's header after an AJAX update. Header is highlighted and shows asc. oder desc. order before the update, but the updated data in table doesn't match this visual sorting part.

Comment #5

Posted on Jul 9, 2012 by Helpful Hippo

The correct behavior after AJAX update on DataTable would be: If initial sorting was defined ==> apply it again. Otherwise ==> reset DataTable's headers to initial state (no highlighting + default state of sort icons).

Comment #6

Posted on Jul 11, 2012 by Massive Ox

Comment deleted

Comment #7

Posted on Jul 11, 2012 by Massive Ox

This problem is affecting us as well. It would be good if sort order was maintained after an AJAX update.

Comment #8

Posted on Aug 14, 2012 by Grumpy Horse

I have the same problem. I have many sortable columns and after ajax update the datatable component don't remember the last sorted column and order. Also couldn't take a successfully sorting, rows appears not sorted.

Comment #9

Posted on Aug 17, 2012 by Helpful Rabbit

Possible solution:

... function sortDefault(widgetTable,colId){ var col = $(widgetTable.jqId + "\\:" + colId); $(col).siblings().removeClass("ui-state-active").find(".ui-sortable-column-icon").removeClass("ui-icon-triangle-1-n ui-icon-triangle-1-s"); $(col).addClass("ui-state-active"); var icon = $(col).find(".ui-sortable-column-icon"); icon.addClass("ui-icon-triangle-1-n"); widgetTable.sort(col.attr("id"),"ASCENDING"); }

... and ...

Comment #10

Posted on Sep 11, 2012 by Quick Rabbit

Same problem for me a;so..... It would be good if sort order was maintained after an AJAX update.

PrimeFaces 3.4

Comment #11

Posted on Dec 13, 2012 by Quick Panda

We have the same problem. Are there any recent results or workarounds?

Comment #12

Posted on Jan 17, 2013 by Swift Rhino

This is expected, default sortBy only works on page load, after it sort state is kept.

Comment #13

Posted on Jan 17, 2013 by Massive Cat

I've posted a workaround for this issue on stackoverflow.com : http://stackoverflow.com/a/14376094/1151983

Although the issue itself won't fix, it would be very cool, if the sort function was added to the table widget officially.

Comment #14

Posted on Mar 21, 2013 by Helpful Panda

I posted a similar workaround, but it instead preserves the user's sorting choices after an update: http://stackoverflow.com/a/15554968/897947

Comment #15

Posted on May 10, 2013 by Swift Wombat

I am waiting for this improvement for a long time! always i modify a row it apeears at the end, is a very inusual behaviour.

Comment #16

Posted on Jun 26, 2013 by Swift Rhino

Issue 2198 has been merged into this issue.

Comment #17

Posted on Jun 26, 2013 by Swift Rhino

Reopen to reconsider.

Comment #18

Posted on Jun 26, 2013 by Swift Rhino

(No comment was entered for this change.)

Comment #19

Posted on Jun 26, 2013 by Quick Wombat

(No comment was entered for this change.)

Comment #20

Posted on May 13, 2014 by Quick Rhino

How is this supposed to be fixed? In PrimeFaces 5.0 I still see that the datatable loses sorting information as soon as an Ajax update is issued on it.

Comment #21

Posted on Jun 29, 2014 by Swift Dog

Is this really fixed? Changing to another page in a paginated datatable causes datatable to lose its sorting (although sort column is highlighted) in version 5.0.2

Comment #22

Posted on Sep 12, 2014 by Grumpy Ox

i've tried and it seems not be be fixed (and some other Major issues with dataTable and lazyLoading neither). I realy like primefaces but the dataTable with lazy loading seems not to be in focus of primefaces development. The issues exist since two years. dataTable with lazy loading is a main component for REAL world applications where someone has to handle REAL data. Would be great if primefaces should be used by REAL applications the issues for dataTable with lazy loading may get higher priority.

description of Workaround can be found here:

http://stackoverflow.com/questions/16622862/primefaces-3-5-multisort-failure-on-pagination-do-we-have-fix

and a good summary on the Workarounds you Need to get up and working with the dataTable and lazy loading can be found here:

http://bolton-janu1991.blogspot.co.at/2013/08/initial-sortorder-for-primeface.html

Comment #23

Posted on Apr 14, 2015 by Swift Ox

With PF 5.0.10 I am seeing a variant of this problem. If a non-lazyload table with single sort is sorted by one column, and correctly shows the up or down sort indicator in that column's header and double-triangle icons in all other column headers, after a refresh, ALL the columns are shown with the single-triangle sort symbol (up or down, depending upon what the actual sorting column had prior to the update). The actual row sort order appears unchanged. Inspection in Firebug shows that after the refresh ALL the columns have ui-state-active style class set (which they shouldn't, but which helps to explain why the single sort triangle is shown in all columns).

Comment #24

Posted on Aug 17, 2015 by Helpful Ox

Primefaces 5.2, and this isn't fixed yet.

Status: Fixed

Labels:
Priority-Medium Type-Defect TargetVersion-4.0 TargetVersion-3.5.8