Joao Victor
Joao Victor

Reputation: 1171

rich:datascroller number of pages based on the total of records, not on the number of rows from the datatable

I don't know if i'm right, but as far as i know, the number of pages shown on a rich:datascroller, is based on the size of the list populating the datatable.

But here's the thing: let's say that in total, there's 20 records to be shown. I just want to query 10 of them, and make it so there's two pages on the datascroller. I can't query all my records, because there can be times that is something over 300.000 records. I can't leave it in the memory. Is there anyway that this can be achieved?

Here's my code so far:

<rich:datascroller for="grdPemissoes" maxPages="5"
    reRender="contentResultadoTable, labelResultados"
    page="#{actionDivisao.pageIndex}"
    pageVar="#{actionDivisao.totalPages}"
    eventsQueue="queueScroller"
</rich:datascroller>
<rich:dataTable id="grdPemissoes" rowClasses=" ,td_cinza"
    value="#{actionDivisao.listaResultados}"
    styleClass="table table-search-result"
    var="divisao" rowKeyVar="row"
    rows="#{actionDivisao.registrosPorPagina}">
                        //columns
</rich:dataTable>

Since there's always 10 records, there's no pages to be shown. I'm using richfaces 3 and jsf 1.2.

Upvotes: 0

Views: 717

Answers (1)

Makhiel
Makhiel

Reputation: 3884

Tables use a dataModel (javax.faces.model.DataModel or a class extending it), if you want to change the default behavior, e.g. return a size different from how many records you have loaded, you will need to implement your own dataModel and pass it to the value attribute of the table:

public class MyDataModel extends org.ajax4jsf.model.ExtendedDataModel {

    @Override
    public int getRowCount() {
        return this.list.size() + 10; // or something
    }

    …
}

You can check an example in the showcase.

Upvotes: 1

Related Questions