PrimeFaces dataTable: how to catch rows-per-page event?

前端 未结 4 1779
小蘑菇
小蘑菇 2021-01-05 07:03

I cretated a PrimeFaces dataTable:



        
4条回答
  •  暖寄归人
    2021-01-05 07:45

    I posted this solution to another question, and I'm sharing it because I hope someone might find it simpler to implement than Daniel's (which still taught me a lot about JQuery!)

    My solution is using Primefaces 5.2.x.

    I found a pretty easy way to implement this, one of the problems I had was that when the onPaginate() method was called, it didn't have the newest selected value.

    So here's what I did to make sure you always had the latest value and could save/load it to the database or a cookie or something (we save to a cookie).

    
            .....
            
            .....
    
    
    

    and then our controller looks like this:

    @Dependent
    @Named
    public class TableController implements Serializable {
        private String rowsPerPage = "25"; //default value
        .....
        public void onPaginate() {
            //save to the cookie
        }
        .....
    }
    

    Basically the magic happens in the remoteCommand, which will fire after the ajax event to insure that controller.rowsPerPage has been properly updated.

提交回复
热议问题