Catalin Kormos wrote:
Looks to me like there a few things that need to be changed when sorting is involved also. For now I found the following, it works for me now, but its possible that i'm wrong, please correct me if I am:
 - the dataset size needs to be fetched independently from the actual data

Yes. You need to do a select count(*) operation to determine the actual number of available rows before fetching the subset of data wanted. There's no way a scroller component can render itself without knowing the full size of the dataset.

 - the  t:dataTable should preserve the sorting and the dataModel.

The first one I needed, because I was asking for the row count before the table is rendered, and the second one its not realy clear to me why is needed, I mean why the "preserveDataModel" should be "true", it works only like this.

I wouldn't think that preserveDataModel would work at all with this approach. This caches the displayed data, which is exactly what you *don't* want to do when you've only got part of the available data loaded into memory.

I don't know why you're having problems with the sorting; there's nothign very complex here:

<t:dataTable
   sortColumn="#{myBean.sortColumn}"
   sortAscending="#{myBean.sortAscending}"
   value="#{myBean.myDataModel}">



public class myBean {
  // add getters and setters for sortColumn, sortAscending

  public DataModel getMyDataModel() {
    // as per wiki page
  }

  public DataPage getDataPage(int startRow, int pageSize) {
    // build sql where-clause to select desired rows of data

    // prefix query with "select count(*) from xx where ...."
    // then execute this to get the number of available rows

    // create the select statement using where-clause
    // add "sort by xxxx" depending on value of this.sortColumn
    // add "ASC" or "DESC" depending on value of this.sortAscending
    // add code to select just the set of desired rows

    // execute the query to get the actual rows, in the desired order
    // create a DataPage object to wrap size+data info, and return it.
  }
}

Reply via email to