3 Replies Latest reply on May 1, 2009 1:59 PM by nbelaevski

    scrollableDataTable custom DataModel and sorting

    tw

      I have a scrollableDataTabel with custom ScrollableTableDataModel. I want to use this to eventually push sorting down to the database.

      I notice that loadData(int startRow, int endRow, SortOrder sortOrder) is called twice whenever a column is sorted. Once to decode the components with previous sort order and then again to render the table with the new sortOrder. I have no input controls in the table. How can I avoid the decode pass that will cause a redundant database query?

      Second issue is the interface of the load method. SortOrder/SortField do not tell me what column is being sorted (id). It only contains the sortExpression. It would be good to have access to the corresponding column ids within this method. Is this a planned enhancement?

        • 1. Re: scrollableDataTable custom DataModel and sorting
          nbelaevski

          Hello,

          It is entirely possible to skip decoding, using some external code and component attributes; however some features of SDT are likely to break then (e.g. selection). Why not cache data loaded on the decode in model and then use it for encode?

          SortField has "name" attribute. Isn't this information enough?

          • 2. Re: scrollableDataTable custom DataModel and sorting
            tw

            Hi Nick,

            The problem I have is that the load(...) method is called twice when I sort the table by clicking on the column header. With a fully database backed sorting, this would force me to first run the query with the previous sort order and then again with the new sort order, which is what I want to avoid. I'm looking for a way to avoid the first query on sorting.

            SortField has a name attribute. This contains the value of sortExpression. Since I'm using the columns tag to setup columns dynamically, this will always be an EL expression, not a column name literal. I'm looking for a way to directly reference the respective column w/o EL evaluation within the load method. I think it would be a good enhancement to provide more contextual information to the load method, including the table and column components.

            • 3. Re: scrollableDataTable custom DataModel and sorting
              nbelaevski

              You can try to use org.ajax4jsf.model.SerializableDataModel. This will allow you to store data used for rendering and not re-fetch it from DB. Please take a look at livedemo example http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=dataModel&cid=4802772 and another example: https://jira.jboss.org/jira/browse/RF-3314 .

              Here is the example that shows fully-functional data table and DB interaction, involving dynamic columns: https://jira.jboss.org/jira/browse/RF-4403 . Please take a look.