Announcement

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

    ListGrid Group Summary updating on add/remove but not on update?

    I am using a List Grid which which I have set up to group on a particular field and then have enabled Group Summaries. While I have found that this works I have noticed that the Group Summary line only updates on an add or remove operation, not on an update. All operations in my case are with setClientOnly and via the addData/updateData/removeData methods on an underlying datasource which the listgrid is linked to.

    What I can clearly see on an update is that the field in the record in question updates inside the list grid and if I enable grid summaries I can clearly see the values in the grid summary fields change too - just the group summary line is not updating just in this particular case. It looks like it only affects updates. Is there any way to make this work or is this a problem with Smartgwt?

    The reason why I want the Group Summaries enabled in the first place is to display a summary of the data within the group via a mix of builtin and custom summary functions. As the number of rows in my application does not normally change, as the data within the records is updated the group summary line no longer reflects the data.

    To demonstrate the problem I have taken one of the samples out of the Showcase. It is a list grid that shows basic information about countries. It has four buttons (add, update continent field, update government field, remove). Records are grouped on the continent field. when I do the following operations we can see:

    Add a country (Continent is North America, Government is Democracy)
    - List Grid: CORRECT - Record is added and displayed correctly inside the correct group based on continent
    - Group Sumary: CORRECT - Group summary is correct based on the records in the list grid
    - Grid Summary: CORRECT - Grid summary is correct based on the records in the list grid

    Update continent (change continent from North America to Europe)
    - List Grid: CORRECT - Record is updated and displayed correctly, Record stays in the North America group even though it is now in Europe
    - Group Summary: WRONG - Group summary remains completely unchanged
    - Grid Summary: CORRECT - Grid summary is updated correctly - it shows the correct information based on the contents of the list grid)

    Update government (change government from Democracy to Monarchy)
    - List Grid: CORRECT - Record is updated and displayed correctly, Record stays in the North America group even though it is now in Europe
    - Group Summary: WRONG - Group summary remains completely unchanged
    - Grid Summary: CORRECT - Grid summary is updated correctly - it shows the correct information based on the contents of the list grid)

    Add a country (Continent is North America, Government is Democracy)
    - List Grid: CORRECT - Record is removed and is no longer displayed inside the correct group based on continent
    - Group Sumary: CORRECT - Group summary is correct based on the records in the list grid
    - Grid Summary: CORRECT - Grid summary is correct based on the records in the list grid

    EDIT: I have found in very specific situations I have found that it does update after two modifications - e.g. if you update an existing row by pressing the Monarchy button and then updat the same row using the Europe button, the record is correctly moved into the Europe group and the Group summaries are updated. Strangely if you do the modifications to a single record in the opposite way (Continent -> Europe first and then Government -> Monarchy) it does not move the record into the correct group or group summary (the modifcations to the individual fields update fine).

    I am using the 27th March nightly build of Smartgwt 3.0 LGPL.

    Thanks in advance ...

    Code:
    package com.missingmatter.testgrid.client;
    		  
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.fields.DataSourceBooleanField;
    import com.smartgwt.client.data.fields.DataSourceDateField;
    import com.smartgwt.client.data.fields.DataSourceFloatField;
    import com.smartgwt.client.data.fields.DataSourceIntegerField;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.types.GroupStartOpen;
    import com.smartgwt.client.types.SummaryFunctionType;
    import com.smartgwt.client.widgets.Canvas;  
    import com.smartgwt.client.widgets.IButton;  
    import com.smartgwt.client.widgets.events.ClickEvent;  
    import com.smartgwt.client.widgets.events.ClickHandler;  
    import com.smartgwt.client.widgets.grid.ListGrid;  
    import com.smartgwt.client.widgets.grid.ListGridField;  
    import com.smartgwt.client.widgets.grid.ListGridRecord;  
    import com.smartgwt.client.widgets.grid.SummaryFunction;
    	  
    import com.google.gwt.core.client.EntryPoint;  
    	  
    public class Testgrid implements EntryPoint
    {  
    	  
        public void onModuleLoad()
        {  
            final DataSource worldXmlDS = new DataSource();  
    
            worldXmlDS.setID("worldDS");  
            
            DataSourceIntegerField pkField = new DataSourceIntegerField("pk");  
            pkField.setHidden(true);  
            pkField.setPrimaryKey(true);  
          
            DataSourceTextField countryCodeField = new DataSourceTextField("countryCode", "Code");  
            countryCodeField.setRequired(true);  
          
            DataSourceTextField countryNameField = new DataSourceTextField("countryName", "Country");  
            countryNameField.setRequired(true);  
          
            DataSourceTextField capitalField = new DataSourceTextField("capital", "Capital");  
            DataSourceTextField governmentField = new DataSourceTextField("government", "Government", 500);  
          
            DataSourceBooleanField memberG8Field = new DataSourceBooleanField("member_g8", "G8");  
          
            DataSourceTextField continentField = new DataSourceTextField("continent", "Continent");   
                  
            worldXmlDS.setFields(pkField, countryCodeField, countryNameField, capitalField, governmentField,  
                        memberG8Field, continentField);  
          
            worldXmlDS.setClientOnly(true); 
                
            Canvas canvas = new Canvas();  
    		  
            final ListGrid countryGrid = new ListGrid();  
            countryGrid.setWidth(1000);  
            countryGrid.setHeight(500);  
            countryGrid.setEmptyCellValue("-");  
            countryGrid.setDataSource(worldXmlDS);  
            countryGrid.setShowAllRecords(true);
    		  
            ListGridField listGridCountryCodeField = new ListGridField("countryCode", "Country Code");  
            ListGridField listGridNameField = new ListGridField("countryName", "Country");  
            ListGridField listGridCapitalField = new ListGridField("capital", "Capital");  
            ListGridField listGridContinentField = new ListGridField("continent", "Continent");  
            ListGridField listGridGovernmentField = new ListGridField("government", "Government");  
            
            listGridCountryCodeField.setSummaryFunction(SummaryFunctionType.COUNT);
            listGridNameField.setSummaryFunction(SummaryFunctionType.COUNT); 
            listGridCapitalField.setSummaryFunction(SummaryFunctionType.COUNT); ; 
            
            listGridContinentField.setSummaryFunction( new SummaryFunction() 
            {
            	public Object getSummaryValue(Record[] p_Records, ListGridField p_Field)
            	{
            		long l_NorthAmericas = 0;
        	
            		for (int l_Index = 0; l_Index < p_Records.length; l_Index++)
            		{  
            			Record l_Record = p_Records[l_Index];  
            			String l_RecordCategory = l_Record.getAttribute("continent");
    				
            			//if ( ( l_RecordCategory != null ) && ( l_RecordCategory.equals("North America") ) )
            			if (  l_RecordCategory.equals("North America") )
            			{
            				l_NorthAmericas++;
            			}
            		}
            		
            		return l_NorthAmericas + " North Americas";  
            	}  
            });
            
            listGridGovernmentField.setSummaryFunction( new SummaryFunction() 
            {
            	public Object getSummaryValue(Record[] p_Records, ListGridField p_Field)
            	{
            		long l_NorthAmericas = 0;
        	
            		for (int l_Index = 0; l_Index < p_Records.length; l_Index++)
            		{  
            			Record l_Record = p_Records[l_Index];  
            			String l_RecordCategory = l_Record.getAttribute("government");
    				
            			//if ( ( l_RecordCategory != null ) && ( l_RecordCategory.equals("Monarchy") ) )
            			if ( l_RecordCategory.equals("Monarchy") )
            			{
            				l_NorthAmericas++;
            			}
            		}
            		
            		return l_NorthAmericas + " Monarchies";  
            	}  
            });
            
            countryGrid.setFields(listGridCountryCodeField, listGridNameField, listGridCapitalField, listGridContinentField, listGridGovernmentField);  
    		           
            countryGrid.setAutoFetchData(true);  
    
            countryGrid.setGroupByField("continent");  
            countryGrid.setGroupStartOpen(GroupStartOpen.ALL);  
            countryGrid.setShowGridSummary(true);
            countryGrid.setShowGroupSummary(true);  
            countryGrid.setShowGroupSummaryInHeader(true);  
            
            IButton addCountry = new IButton("Add new country");  
            addCountry.addClickHandler(new ClickHandler()
            {  
            	public void onClick(ClickEvent event)
            	{  
            		ListGridRecord rec = new ListGridRecord();  
            		int number = getNextNumber();  
            		rec.setAttribute("pk", number);
            		rec.setAttribute("countryCode", "A" + number);  
            		rec.setAttribute("countryName", "Country " + number);  
            		rec.setAttribute("capital", "Capital " + number);  
            		rec.setAttribute("continent", "North America");  
            		rec.setAttribute("government", "Democracy");
            		worldXmlDS.addData(rec);                 
            	}             
            });  
            addCountry.setLeft(0);  
            addCountry.setTop(600);  
            addCountry.setWidth(140);  
    		          
            IButton changeContinent = new IButton("Continent -> Europe");  
            changeContinent.addClickHandler(new ClickHandler() {  
                public void onClick(ClickEvent event) {  
                    ListGridRecord selectedRecord = countryGrid.getSelectedRecord();  
                    if(selectedRecord != null) {  
                        selectedRecord.setAttribute("continent", "Europe");  
                        worldXmlDS.updateData(selectedRecord);  
                    }  
                }             
            });  
            changeContinent.setLeft(160);  
            changeContinent.setTop(600);  
            changeContinent.setWidth(140);  
            
            IButton changeGovernment = new IButton("Government -> Monarchy");  
            changeGovernment.addClickHandler(new ClickHandler() {  
                public void onClick(ClickEvent event) {  
                    ListGridRecord selectedRecord = countryGrid.getSelectedRecord();  
                    if(selectedRecord != null) {  
                        selectedRecord.setAttribute("government", "Monarchy");  
                        worldXmlDS.updateData(selectedRecord);  
                    }  
                }             
            });  
            changeGovernment.setLeft(320);  
            changeGovernment.setTop(600);  
            changeGovernment.setWidth(140);  
            
            IButton removeCountry = new IButton("Remove Country");  
            removeCountry.addClickHandler(new ClickHandler() {  
                public void onClick(ClickEvent event) {  
                    ListGridRecord selectedRecord = countryGrid.getSelectedRecord();  
                    if(selectedRecord != null) {  
                        worldXmlDS.removeData(selectedRecord);  
                    }  
                }             
            });  
            removeCountry.setLeft(480);  
            removeCountry.setTop(600);  
            removeCountry.setWidth(140); 
            
            canvas.addChild(countryGrid);  
            canvas.addChild(addCountry);  
            canvas.addChild(changeContinent);
            canvas.addChild(changeGovernment);
            canvas.addChild(removeCountry);
    		  
            canvas.draw();  	          
    	}  
    		      
    	private int counter = 1;  
    		      
    	private int getNextNumber()
    	{  
    		return counter++;  
    	}  
    }

    #2
    As it seems I have little alternative at this point I have tried to workaround the issue however the results I have got not desirable/workable.

    What I tried to do is force the group summary line to update by adding a new "fake" record and then removing it. While this forces the group summaries to be updated it also does mean that the fake record is visible very briefly. Considering my application will be doing a lot of small updates on multiple records every X many seconds this will not work very well.

    I subsequently tried to remove this side-effect by applying a filter so that the fake record will not appear - this stops the fake record from appearing however it also means that the group summary line is not updated either so I am back to the original problem.

    So at this stage I am still in the same position as my original post above - modifications to records in the list grid are coming through however the group summaries are not updating like they should.

    NOTE: I have moved to the latest nightly build of Smartgwt 3.0 when doing the above testing.

    Comment


      #3
      hace you tried countryGrid.recalculateSummaries() after update records? or have you tried a delay and then call recalculateSummaries() ?

      Comment


        #4
        Originally posted by cventura
        hace you tried countryGrid.recalculateSummaries() after update records? or have you tried a delay and then call recalculateSummaries() ?
        Thanks - I did not know that this function existed. It worked once I used recalculateSummaries() in the callback routine for the updateData.

        Comment

        Working...
        X