p:datatable loses sort column and order after ajax refresh

后端 未结 8 1650
攒了一身酷
攒了一身酷 2020-12-17 19:38

I have a button on a page that causes my data table to refresh via an AJAX request. Something like this:




        
8条回答
  •  南方客
    南方客 (楼主)
    2020-12-17 20:31

    First of all, there is an open ticket on the PrimeFaces Issue Tracker, which targets this question but was recently labeled as "won't fix".

    Nevertheless, I found a nice workaround. The sorting of PrimeFaces tables can be triggered by calling an undocumented JavaScript method on the datatable's widget. The following might not work for future releases of PrimeFaces, but it does for 3.4.2:

    Just add the following to your component, which triggers the update:

    oncomplete="myTableWidget.sort($(PrimeFaces.escapeClientId('#{p:component('sortColumnId')}')), 'ASCENDING')"
    

    The table might look like this:

    
        ...
    
        
            
                
            
            
        
    
    
    

    So updating the table could work like this.

    
    

提交回复
热议问题