Not very clear on the question but there is a countQuery variable that took the same sql query but with a count instead to handle pagination. Also, the sorting is based of what the client request contains but there is a default in the sql too for situations where the client doesn't specify.