You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by geirgp <ge...@gmail.com> on 2007/06/14 15:38:18 UTC

dataTable - only show first 10 results

I'm totally new to JavaScript and JSF, so I'm seeking a bit of advise here.. 

I want to hide all but the first 10 rows in a dataTable and have a link
(javascript) "Show all" that reveals the hidden rows when clicked. 

Any ideas?

Thanks in advance
-- 
View this message in context: http://www.nabble.com/dataTable---only-show-first-10-results-tf3921795.html#a11120357
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: dataTable - only show first 10 results

Posted by Andrew Robinson <an...@gmail.com>.
Why not limit the number of rows bound to the DataModel in the backing
bean? Then have an action listener on the show all button that changes
the method to return the data without the limit.

private boolean limitRows = true;
private List data;
public boolean isLimitRows() { return this.limitRows; }
public void setLimitRows(boolean limitRows) { this.limitRows = limitRows; }
public List getData() {
  if (limitRows) {
    return data.subList(0, Math.max(10, data.size()));
  } else {
    return data;
  }
}

<h:dataTable value="#{bean.data}" var="_row">
  <f:facet name="header">
    <h:panelGroup>
      <h:commandLink value="Show all" rendered="#{bean.limitRows}">
        <t:updateActionListener property="#{bean.limitRows}" value="#{false}" />
      </h:commandLink>
      <h:commandLink value="Show first 10" rendered="#{not bean.limitRows}">
        <t:updateActionListener property="#{bean.limitRows}" value="#{true}" />
      </h:commandLink>
    </h:panelGroup>
  </f:facet>
  <h:column>
  ...
</h:dataTable>


On 6/14/07, geirgp <ge...@gmail.com> wrote:
>
> I'm totally new to JavaScript and JSF, so I'm seeking a bit of advise here..
>
> I want to hide all but the first 10 rows in a dataTable and have a link
> (javascript) "Show all" that reveals the hidden rows when clicked.
>
> Any ideas?
>
> Thanks in advance
> --
> View this message in context: http://www.nabble.com/dataTable---only-show-first-10-results-tf3921795.html#a11120357
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>