javagwtdatagridmvp4g

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 ?


Solution

  • 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