1. #1
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    4
    gslender is on a distinguished road

      0  

    Default [FIXED] GroupSummaryView does not update when group property is changed

    [FIXED] GroupSummaryView does not update when group property is changed


    GroupSummaryView does not update when group property is changed, though the underlying store is updated and other property items also update, the rows is not moved from one group to another.

    This leads to another thought - how would you update a row from one group to another without reloading the entire store/grid? Can you do that?

    The code below shows the problem....

    Code:
    public class UpdateTotalsGridTest implements EntryPoint {
    
      public void onModuleLoad() {
        List<Task> tasks = new ArrayList<Task>();
        tasks.add(new Task(100, "Ext Forms: Field Anchoring", 112, "Integrate 2.0 Forms with 2.0 Layouts", 6, 150, "06/24/2007"));
        tasks.add(new Task(100, "Ext Forms: Field Anchoring", 113, "Implement AnchorLayout", 4, 150, "06/25/2007"));
        
        tasks.add(new Task(101, "Ext Grid: Single-level Grouping", 101, "Add required rendering 'hooks' to GridView",6 , 100, "07/01/2007"));
        
        tasks.add(new Task(102, "Ext Grid: Summary Rows", 105, "Ext Grid plugin integration",4 , 125, "07/01/2007"));
      
    
        final GroupingStore<Task> store = new GroupingStore<Task>();
        store.groupBy("project");
        store.add(tasks);
    
        List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
    
        SummaryColumnConfig desc = new SummaryColumnConfig("description", "Task", 80);
        desc.setSummaryType(SummaryType.COUNT);
        desc.setSummaryRenderer(new SummaryRenderer() {
          public String render(Double value, Map<String, Double> data) {
            return value > 1 ? "(" + value.intValue() + " Tasks)" : "(1 Task)";
          }
        });
        desc.setEditor(new CellEditor(new TextField<String>()));
        
        SummaryColumnConfig project = new SummaryColumnConfig("project", "Project", 80);
        SummaryColumnConfig due = new SummaryColumnConfig("due", "Due Date", 20);
        
            
        SummaryColumnConfig estimate = new SummaryColumnConfig("estimate", "Estimate", 20);
        estimate.setRenderer(new GridCellRenderer() {
          public String render(ModelData model, String property, ColumnData config, int rowIndex,
              int colIndex, ListStore store) {
            return model.get(property) + " hours";
          }
        });
        estimate.setSummaryType(SummaryType.SUM);
        estimate.setSummaryRenderer(new SummaryRenderer() {
          public String render(Double value, Map<String, Double> data) {
            return value.intValue() + " hours";
          }
        });
        estimate.setEditor(new CellEditor(new NumberField()));
        
        SummaryColumnConfig rate = new SummaryColumnConfig("rate", "Rate", 20);
        rate.setNumberFormat(NumberFormat.getCurrencyFormat());
        rate.setSummaryFormat(NumberFormat.getCurrencyFormat());
        rate.setSummaryType(SummaryType.AVG);
        rate.setEditor(new CellEditor(new NumberField()));
    
        SummaryColumnConfig cost = new SummaryColumnConfig("cost", "Cost", 20);
        cost.setSummaryFormat(NumberFormat.getCurrencyFormat());
        cost.setSummaryType(new SummaryType() {
          @Override
          public double render(Object v, ModelData m, String field, Map<String, Object> data) {
            if (v == null) {
              v = 0d;
            }
            Task task = (Task)m;
            return ((Double)v).doubleValue() + (task.getEstimate() * task.getRate());
          }
        
        });
        cost.setRenderer(new GridCellRenderer() {
          public String render(ModelData model, String property, ColumnData config,
              int rowIndex, int colIndex, ListStore store) {
            Task task = (Task) model;
            return NumberFormat.getCurrencyFormat().format(task.getRate() * task.getEstimate());
          }
        });
    
        columns.add(desc);
        columns.add(project);
        columns.add(due);
        columns.add(estimate);
        columns.add(rate);
        columns.add(cost);
        ColumnModel cm = new ColumnModel(columns);
    
        GroupSummaryView summary = new GroupSummaryView();
        summary.setForceFit(true);
        summary.setShowGroupedColumn(false);
    
        EditorGrid<Task> grid = new EditorGrid<Task>(store, cm);
        grid.setBorders(true);
        grid.setView(summary);
        grid.getView().setShowDirtyCells(false);
        
        ContentPanel panel = new ContentPanel();
        panel.setHeading("Sponsored Projects");
        panel.setIconStyle("icon-table-framed");
        panel.setCollapsible(true);
        panel.setFrame(true);
        panel.setBounds(10, 10, 700, 450);
        panel.setLayout(new FitLayout());
        panel.add(grid);
        
        ToolButton tb = new ToolButton("x-tool-gear");
        panel.getHeader().addTool(tb);
        tb.addSelectionListener(new SelectionListener<ComponentEvent>(){
            public void componentSelected(ComponentEvent ce) {
                System.out.println("gear clicked");
                printStore(store);
                Task t = store.getAt(0);
                store.getRecord(t).set("project", "Ext Grid: Summary Rows"); //<<< this is updated BUT view isn't
                store.getRecord(t).set("estimate", 1.0); //<<< this is updated AND view is
                store.commitChanges();
                store.update(t);
                System.out.println("store updated");
                printStore(store);
            }});
    
        RootPanel.get().add(panel);
      }
      
      private void printStore(Store<Task> s) {
          List<Task> l = s.getModels();
          for (Task t : l) {
              System.out.println(t);
          }
      }
    }

  2. #2
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    4
    gslender is on a distinguished road

      0  

    Default


    update - calling view.groupBy() resolves the problem, but an issue still exists with nested BeanModel's whereby the record update via set does not work if you just add the new POJO to the bean, you have to wrap the POJO in a created bean and set that via the record.

    That last step (wrapping the pojo) doesn't seem obvious as originally this was not required when creating the beans, but due to the beanmodel nested set etc, this is required.