GWT CellBrowser- how to always show all values?

1.5k views Asked by At

GWT's CellBrowser is a great way of presenting dynamic data.

However when the browser contains more rows than some (seemingly) arbitrary maximum, it offers a "Show More" label that the user can click to fetch the unseen rows.

How can I disable this behavior, and force it to always show every row?

alt text

5

There are 5 answers

0
Thomas Broyer On BEST ANSWER

There are several ways of getting rid of the "Show More" (which you can combine):

  • In your TreeViewModel, in your NodeInfo's setDisplay or in the DataProvider your give to the DefaultNodeInfo, in onRangeChange: overwrite the display's visible range to the size of your data.

  • Extend CellBrowser and override its createPager method to return null. It won't change the list's page size though, but you can set it to some very high value there too.

0
luijar On

The easiest way to do this is by using the:

cellTree.setDefaultNodeSize(Integer.MAX_VALUE);

method on your Cell Tree. You must do this before you begin expanding the tree.

0
Stefan Haebler On

The below CellBrowser removes the "Show More" text plus loads all available elements without paging.

public class ShowAllElementsCellBrowser extends CellBrowser {

    public ShowAllElementsCellBrowser(TreeViewModel viewModel, CellBrowser.Resources resources) {
        super(viewModel, null, resources);
    }

    @Override
    protected <C> Widget createPager(HasData<C> display) {
        PageSizePager pager = new PageSizePager(Integer.MAX_VALUE);

        // removes the text "Show More" during loading
        display.setRowCount(0);

        // increase the visible range so that no one ever needs to page
        display.setVisibleRange(0, Integer.MAX_VALUE);
        pager.setDisplay(display);

        return pager;
    }
}
0
MarioC On

I found a valid and simple solution in setting page size to the CellBrowser's builder. Hope this will help.

CellBrowser.Builder<AClass> cellBuilder = new CellBrowser.Builder<AClass>(myModel, null); cellBuilder.pageSize(Integer.MAX_VALUE); cellBrowser = cellBuilder.build();

0
zhivko On

My workaround is to navigate through elements of treeview dom to get "show more" element with

public static List<Element> findElements(Element element) {
    ArrayList<Element> result = new ArrayList<Element>();
    findShowMore(result, element);  return result; }

private static void findShowMore(ArrayList res, Element element) {
    String c;

    if (element == null) {      return;     }

    if (element.getInnerText().equals("Show more")) {       res.add(element);
    }

    for (int i = 0; i < DOM.getChildCount(element); i++) {      Element
child = DOM.getChild(element, i);       findShowMore(res, child);   } }

and than use:

if (show) {   element.getStyle().clearDisplay(); } else {  
element.getStyle().setDisplay(Display.NONE); }