Announcement

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

    ListGrid:setEditorCustomizer DateItem format issue

    PROBLEM: When edit cell is enabled and I edit the cell and leave it (see below code for exact setup of grid), the edits are there and save has not been initiated yet. Then I edit that cell again to undo using the escape key. The grid shows the edit being undone, but the edit values still exist. My code shows summary values of the column and must determine to whether to use the edit value or the original value of that cell. The only way I know that it has an edit value is using grid.getEditValues for the record.

    SOLUTION: Shouldn't the edit value for that record's cell not have a edit value?

    The documentation indicates that EscapeKeyEditAction.CANCEL "cancels the current edit and discards edit values".


    1. SNAPSHOT_v10.1d_2015-07-30/Enterprise Deployment 2015-07-30

    2. Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:26.0) Gecko/20100101 Firefox/26.0

    Here is the setup of my grid:

    Code:
    	grid.setEscapeKeyEditAction(EscapeKeyEditAction.CANCEL);
    	grid.setCanEdit(true);  
    	grid.setModalEditing(true);  
            grid.setEditEvent(ListGridEditEvent.DOUBLECLICK);  
            grid.setListEndEditAction(RowEndEditAction.NEXT);  
            grid.setEditByCell(true);
            grid.setCanSelectCells(true);
            grid.setAutoSaveEdits(false);  
            grid.setShowAllRecords(true);  
            grid.setCanReorderRecords(true);  
            grid.setIncludeInSummaryProperty("_include");
    When I hit the escape key, then the editor exits and I recompute the summary:

    Code:
    		grid.addEditorExitHandler(new EditorExitHandler() {
    
    			@Override
    			public void onEditorExit(EditorExitEvent event) {
    				if(event.getRowNum() > 1)
    					editGrid.recalculateSummaries();
    			}
    			
    		});
    Here is the summary function that does get call when I move from the cell after editing or hitting the escape key when I'm editing the cell.
    Code:
    		SummaryFunction sf = new SummaryFunction() {
    
    			@Override
    			public Object getSummaryValue(Record[] records,
    					ListGridField field) {
    				Double total = 0.0;
    				String sval = null;
    				Object oval = null;
    				String fname = field.getName();
    				int index=0;
    				for(ListGridRecord record: grid.getRecords())
    				{
    					if(2 > (index = grid.getRecordIndex(record)))
    						continue;
    					
    					@SuppressWarnings("unchecked")
    					Map<String,Object> ed = grid.getEditValues(record);
    					
    					if(ed.containsKey(fname))
    					{
    						oval = ed.get(fname);
    						SC.logWarn(fname + " Edit value = " + oval.toString());
    						total += Double.valueOf((String) oval);
    					}	else 
    					if(null != (sval = record.getAttribute(fname)))
    					{
    						total += Double.valueOf(sval);
    						SC.logWarn(fname + "(" + index + ") Stat value = " + sval.toString());
    					}
    
    				}
    				return (Object) total;
    			}
    			
    		};
    Last edited by michaeljseo; 31 Jul 2015, 11:03.

    #2
    Sorry, for a claim of a subtle bug like this in a heavily customized grid, partial code won't do. If you think a framework bug is at fault, try creating a minimal, ready-to-run test case starting from a Showcase example and adding minimal changes until you can reproduce the claimed bug.

    Comment


      #3
      I understand.

      I modified the Grid Summaries example in the regular showcase.

      Modifications allow user to modify grid cells without saving upon exit of the cell (countryGrid.setAutoSaveEdits(false)). The summary should reflect the modifications using my summary function.

      Note that when I edit the already edited field and hit the escape key (to undo the edit), then the summary does not reflect that since I grab the edit values for that row and the edit value has not been discarded.


      Code:
          public void onModuleLoad() {  
          	  
              final ListGrid countryGrid = new ListGrid();  
              countryGrid.setWidth(550);  
              countryGrid.setHeight(224);  
              countryGrid.setShowAllRecords(true);  
              countryGrid.setCellHeight(22);  
              // use server-side dataSource so edits are retained across page transitions  
              countryGrid.setDataSource(CountryXmlDS.getInstance());  
        
              ListGridField countryCodeField = new ListGridField("countryCode", "Flag", 40);  
              countryCodeField.setAlign(Alignment.CENTER);  
              countryCodeField.setType(ListGridFieldType.IMAGE);  
              countryCodeField.setImageURLPrefix("flags/16/");  
              countryCodeField.setImageURLSuffix(".png");  
              countryCodeField.setCanEdit(false);  
        
              ListGridField nameField = new ListGridField("countryName", "Country");  
              ListGridField continentField = new ListGridField("continent", "Continent");  
              ListGridField memberG8Field = new ListGridField("member_g8", "Member G8");  
              ListGridField populationField = new ListGridField("population", "Population");  
              populationField.setType(ListGridFieldType.INTEGER);  
              populationField.setCellFormatter(new CellFormatter() {  
                  public String format(Object value, ListGridRecord record, int rowNum, int colNum) {  
                      if(value == null) return null;  
                      try {  
                          NumberFormat nf = NumberFormat.getFormat("0,000");  
                          return nf.format(((Number) value).longValue());  
                      } catch (Exception e) {  
                          return value.toString();  
                      }  
                  }  
              });
              
              // ADDED summary function to see what's going on
              populationField.setShowGridSummary(true);
      		SummaryFunction sf = new SummaryFunction() {
      
      			@Override
      			public Object getSummaryValue(Record[] records,
      					ListGridField field) {
      				Double total = 0.0;
      				String sval = null;
      				Object oval = null;
      				String fname = field.getName();
      				int index=0;
      				for(ListGridRecord record: countryGrid.getRecords())
      				{
      					index = countryGrid.getRecordIndex(record);
      					
      					@SuppressWarnings("unchecked")
      					Map<String,Object> ed = countryGrid.getEditValues(record);
      					
      					if(ed.containsKey(fname))
      					{
      						oval = ed.get(fname);
      						SC.logWarn(fname + "(" + index + ") Edit value = " + oval.toString());
      						total += Double.valueOf((String) oval.toString());
      					}	else 
      					if(null != (sval = record.getAttribute(fname)))
      					{
      						total += Double.valueOf(sval);
      						SC.logWarn(fname + "(" + index + ") Stat value = " + sval.toString());
      					}
      
      				}
      				return (Object) total;
      			}
      			
      		};
      		populationField.setSummaryFunction(sf);
      
              ListGridField independenceField = new ListGridField("independence", "Independence");  
              countryGrid.setFields(countryCodeField, nameField,continentField, memberG8Field, populationField, independenceField);  
        
              
              countryGrid.setAutoFetchData(true);  
              countryGrid.setCanEdit(true);  
      
              //MODIFIED
              //countryGrid.setEditEvent(ListGridEditEvent.CLICK);  
              countryGrid.setEditEvent(ListGridEditEvent.DOUBLECLICK);  
              
              countryGrid.setEditByCell(true);  
               
              // ADDED
              countryGrid.setModalEditing(true);  
              countryGrid.setCanSelectCells(true);
              countryGrid.setAutoSaveEdits(false);  
              countryGrid.setShowAllRecords(true);  
              countryGrid.setShowGridSummary(true);
              countryGrid.addEditorExitHandler(new EditorExitHandler() {
      
      			@Override
      			public void onEditorExit(EditorExitEvent event) {
      				countryGrid.recalculateSummaries();
      			}
      			
      		});
              
              countryGrid.draw();
          }

      Comment


        #4
        What's actually happening here is that the editor exit handler is firing before the edit values have been discarded, so your explicit call to "recalculateSummaries" is occurring before the edit values have been discarded.

        However there's a more fundamental issue here - you shouldn't need to explicitly call recalculate summaries to get the summary row to update as the user changes (or clears) the edit values. This should be happening automatically and indeed if you remove the call in your test case, you will see the summary row being updated when the user first edits a cell (though it does fail to update back to the original value when the user hits "escape" to cancel the edit).

        We've now made a framework change to remedy this. Please try the next nightly build (5.1 branch, dated Aug 1 or above) to get the fix.

        Regards
        Isomorphic Software

        Comment


          #5
          Originally posted by Isomorphic View Post
          What's actually happening here is that the editor exit handler is firing before the edit values have been discarded, so your explicit call to "recalculateSummaries" is occurring before the edit values have been discarded.

          However there's a more fundamental issue here - you shouldn't need to explicitly call recalculate summaries to get the summary row to update as the user changes (or clears) the edit values. This should be happening automatically and indeed if you remove the call in your test case, you will see the summary row being updated when the user first edits a cell (though it does fail to update back to the original value when the user hits "escape" to cancel the edit).

          We've now made a framework change to remedy this. Please try the next nightly build (5.1 branch, dated Aug 1 or above) to get the fix.

          Regards
          Isomorphic Software
          Thank you!

          I grabbed the latest build and now my summary behaves nicely.

          Comment

          Working...
          X