Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Problem of addFacet/setFixedFacetValue in CubeGrid

    I use the sample of "basic CubeGrid" by adding three listGrid: origin list, row list and column list. The user can hide the facet that he doesn't want to see by dragging it to the origin list; and can review the facet by dragging it to the row or column list. The code is:
    Code:
    public class BasicCubeGrid implements EntryPoint {
    
        @Override
        public void onModuleLoad() {
            ListGrid originList = createDragListGrid();
            originList.setFields(new ListGridField("title", "Origin"));
    
            ListGridRecord region = new ListGridRecord();
            region.setAttribute("id", "region");
            region.setAttribute("title", "Region");
            
            final ListGrid rowList = createDragListGrid();
            rowList.setFields(new ListGridField("title", "Row"));
            rowList.setData(new Record[] { region });
    
            final ListGrid colList = createDragListGrid();
            colList.setFields(new ListGridField("title", "Column"));
    
            final CubeGrid cubeGrid = new CubeGrid();
            cubeGrid.setData(ProductRevenueData.getData());
    
            cubeGrid.setWidth100();
            cubeGrid.setHeight100();
            cubeGrid.setHideEmptyFacetValues(true);
            cubeGrid.setShowCellContextMenus(true);
    
            final NumberFormat numberFormat = NumberFormat.getFormat("0,000");
    
            cubeGrid.setCellFormatter(new CellFormatter() {
                @Override
                public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                    if (value == null)
                        return null;
                    try {
                        return numberFormat.format(((Number) value).longValue());
                    } catch (Exception e) {
                        return value.toString();
                    }
                }
            });
    
            cubeGrid.setColumnFacets("quarter", "month", "metric");
            cubeGrid.setRowFacets("region", "product");
    
            originList.addRecordDropHandler(new RecordDropHandler() {
    
                @Override
                public void onRecordDrop(RecordDropEvent event) {
                    String facetId = event.getDropRecords()[0].getAttribute("id");
    
                    cubeGrid.setFixedFacetValue(facetId, "Eastern U.S.");
    
                }
            });
    
            rowList.addRecordDropHandler(new RecordDropHandler() {
    
                @Override
                public void onRecordDrop(RecordDropEvent event) {
    
                    String facetId = event.getDropRecords()[0].getAttribute("id");
    
                    if (cubeGrid.getFacet(facetId) != null) {
                        cubeGrid.addRowFacet(facetId);
                    }
                }
    
            });
    
            colList.addRecordDropHandler(new RecordDropHandler() {
    
                @Override
                public void onRecordDrop(RecordDropEvent event) {
    
                    String facetId = event.getDropRecords()[0].getAttribute("id");
    
                    if (cubeGrid.getFacet(facetId) != null) {
                        cubeGrid.addColumnFacet(facetId);
    
                    }
                }
    
            });
    
            HStack stack = new HStack();
            stack.setWidth100();
            stack.setHeight100();
            stack.setMembersMargin(20);
            stack.addMember(originList);
            stack.addMember(rowList);
            stack.addMember(colList);
            stack.addMember(cubeGrid);
            stack.draw();
    
        }
    
        private ListGrid createDragListGrid() {
    
            ListGrid listGrid = new ListGrid();
            listGrid.setCanSort(false);
            listGrid.setShowSortArrow(SortArrow.NONE);
    
            listGrid.setSelectionType(SelectionStyle.SINGLE);
    
            listGrid.setCanDragRecordsOut(true);
            listGrid.setCanAcceptDroppedRecords(true);
            listGrid.setCanReorderRecords(true);
    
            listGrid.setDragDataAction(DragDataAction.MOVE);
            listGrid.setHeight(100);
            return listGrid;
        }
      
    }
    First, the facet "Region" appears in the row list. I can drag it to the column list to show it as a column, then drag it to the origin list to hide it. Until now, it works fine; but then when I try to drag it to the row facet, a JS exception is thrown:
    Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError): this.rowFields[i][0] is undefined
    fileName: http://127.0.0.1:8888/basicCubeGrid/sc/modules/ISC_Analytics.js
    lineNumber: 445
    I have checked that there is a fixedFacetValue on region when the addRowFacet() is called. But why it can not get the rowFields on region?
    Thank you for any help.
Working...
X