开发者

GWT CellBrowser- how to always show all values?

开发者 https://www.devze.com 2023-02-04 04:31 出处:网络
GWT\'s CellBrowser is a great way of presenti开发者_运维问答ng dynamic data. However when the browser contains more rows than some (seemingly) arbitrary maximum, it offers a \"Show More\" label that

GWT's CellBrowser is a great way of presenti开发者_运维问答ng 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?

GWT CellBrowser- how to always show all values?


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.


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;
    }
}


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();


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.


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); }
0

精彩评论

暂无评论...
验证码 换一张
取 消