Sorting is not working in datatable in PrimeFaces?

后端 未结 7 2424
感情败类
感情败类 2020-12-15 07:13

Sorting is not working in datatable in PrimeFaces. Please suggest.

See below my .xhtml file



  

        
相关标签:
7条回答
  • 2020-12-15 07:43

    My Service had:

    public List<PlayerEntity> getAllPlayers() {
        return playerDao.readAll();
    }
    

    but that was wrong, because when I was calling getAllPlayers() from table

    <p:dataTable id="data" value="#{myBean.allPlayers}"/>
    

    I got from DAO refreshed data but still unordered. Instead of that I've created List field and method to update the List

    private List<PlayerEntity> allPlayers = new ArrayList<PlayerEntity>();  
    
    public void updateAllPlayers(){
        this.allPlayers = playerDao.readAll();
    }
    

    which method I'm running on bean initialization

    public void setPlayerDao(PlayerDao playerDao) {
        this.playerDao = playerDao;
        updateAllPlayers();
    }
    

    and after Add, Delete or Modiffy the List

    public boolean createPlayer(PlayerEntity playerEntity) {
        (...)
        updateAllPlayers();
        return true;
    }
    

    Now my Service has

    public List<PlayerEntity> getAllPlayers() {
        return this.allPlayers;
    }
    

    and that solved my problem with sorting data in Primefaces table.

    0 讨论(0)
提交回复
热议问题