简体   繁体   中英

merge column header in DataGrid or cellTable in GWT 2.4

I want to know the workaround used to have colspan in DataGrid or CellTable

I saw the the GWT showcase : http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCustomDataGrid

but there is no TableRowBuilder and AbstractHeaderOrFooterBuilder in GWT 2.4

I also found that CellTableBuilder API is good too to this purpose but it's not available in GWT 2.4

So I want to know if there is another trick to merge columns header in GWT 2.4 ?

Or how to get the column header using the DOM ?

Here is what I've done to solve this problem in GWT 2.4.

I've used DOM like this

Element thead = view.datagrid.getElement().getElementsByTagName("thead").getItem(0);
    Element tr;
        tr = thead.getElementsByTagName("tr").getItem(0);
    for (int i = 0; i < tr.getChildCount(); i++) {
        Element th = tr.getElementsByTagName("TH").getItem(i);
        String headerText = th.getInnerHTML();
        String sortHeader = "";
        String colspanValue = th.getAttribute("colspan");
        if (th.getChildCount() == 1) {
            Element div = th.getElementsByTagName("DIV").getItem(0);
            sortHeader = null != div ? div.getElementsByTagName("DIV").getItem(1).getInnerHTML()
                    : "";
        }
        if (sortHeader.equalsIgnoreCase("COLUMHEADER1") && colspanValue.equals("1")) {
            th.setAttribute("colspan", "2");
            Element thNext = tr.getElementsByTagName("TH").getItem(i + 1);
            thNext.setAttribute("style", "display: none !important");
        }

}

and for the first start I've used a timer (1sec is the min) like this

 new Timer() {
        @Override
        public void run() {
            view.datagrid.setVisible(true);
            //call to merge column code or function
        }
    }.schedule(1000);

"view." is used because the main class is a presenter

EDIT: display:none is used for the sort issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM