Announcement

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

    Group summary update on select

    Hi

    I am using grid summary and group summary in checkbox selectable grid. I want to update summary according to selections (eg. 1 / 5). This works for grid summaries so that i call refreshFields on selection and calculate the correct summary in summary function. Group summaries use the same summary function but they are not updated on selection. If I collapse and expand group then group summary is updated. So my question is how to update group summaries on selection ?

    Using Gwt 1.7.1, SmartGwt rev 1020, Win Xp, Hosted mode + firefox + chrome

    #2
    You should see that a redraw() causes any customized getGroupTitle() to be called again so that you can provide a new summary. If this does not seem to be the case please provide a standalone test case demonstrating the problem.

    Comment


      #3
      I tried to check if getGroupTitle was called but didn't see it. Only saw getSummary called. So here is small test case which shows the problem.

      First group by column Test then select some records. Grid summary is updated on every selection but group summary isnt.

      Code:
      public class HelloWorld implements EntryPoint {
      
      	public void onModuleLoad() {
      		if (!GWT.isScript()) {
      			KeyIdentifier debugKey = new KeyIdentifier();
      			debugKey.setCtrlKey(true);
      			debugKey.setKeyName("D");
      			Page.registerKey(debugKey, new KeyCallback() {
      				public void execute(String keyName) {
      					SC.showConsole();
      				}
      			});
      		}
      
      		final ListGrid grid = new ListGrid();
      		grid.setWidth(600);
      		grid.setHeight(400);
      		grid.setAlternateRecordStyles(true);
      		grid.setShowAllRecords(false);
      		grid.setSelectionType(SelectionStyle.SIMPLE);
      		grid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
      		grid.setShowGridSummary(true);
      		grid.setShowGroupSummary(true);
      
      		ListGridField nameField = new ListGridField("name", "Name");
      		nameField.setShowGridSummary(true);
      		nameField.setShowGroupSummary(true);
      		nameField.setSummaryFunction(new SummaryFunction() {
      			public Object getSummaryValue(Record[] records, ListGridField field) {
      				int selected = 0;
      				int total = 0;
      				for (Record r : records) {
      					if (r.getAttributeAsBoolean("selected")) {
      						selected++;
      					}
      				}
      				total = records.length;
      				return selected + " / " + total;
      			}
      		});
      		
      		ListGridField testField = new ListGridField("test", "Test");
      		testField.setShowGridSummary(false);
      		testField.setShowGroupSummary(false);
      		
      		grid.setFields(nameField, testField);
      
      		grid.addSelectionChangedHandler(new SelectionChangedHandler() {
      			public void onSelectionChanged(SelectionEvent event) {
      				// This is workaround for getSelection bug 301
      				Record r = event.getRecord();
      				if (r.getAttributeAsBoolean("selected")) {
      					r.setAttribute("selected", false);
      				} else {
      					r.setAttribute("selected", true);
      				}
      				// This should update also group summaries
      				grid.refreshFields();
      			}
      		});
      
      		for (int i = 0; i < 10; i++) {
      			ListGridRecord r = new ListGridRecord();
      			r.setAttribute("id", i);
      			r.setAttribute("name", i);
      			r.setAttribute("test", "Test");
      			r.setAttribute("selected", false);
      
      			grid.addData(r);
      		}
      
      		grid.draw();
      
      	}
      }

      Comment


        #4
        Hi,

        what is the recommended way to ask for a redraw (actually just re-evaluate) the summary functions when selection changes?

        I find that refreshFields() performs the re-evaluate twice (because of unselect and select event), so a markForRedraw() would be better here to do it only once, but this doesn't work. Also not on grid.getParentElement().markForRedraw() which is where the summary row Canvas should be child of.

        Comment


          #5
          refreshFields() updates the list of visible fields. It does not necessarily cause a redraw().

          markForRedraw() causes a redraw and will update summaries.

          No need to call markForRedraw() on a parent. The summary row is part of the grid.

          Comment


            #6
            Unfortunately, calling grid.markForRedraw() does not fire the SummaryFunction set on a ListGridField on that grid. Calling grid.refreshFields() does.

            Comment


              #7
              You're correct - sorry for the confusion here.
              We've now added an explicit API for this: listGrid.recalculateSummaries()
              This API will be present in the next nightly build.

              Comment


                #8
                Thanks, new API works great!

                build 2010-11-12

                Comment

                Working...
                X