Announcement

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

    RecordSummaryFunctions not called after grid.setData()

    I am populating a ListGrid via setData() and supplying a list of records. The grid includes ListGridFieldType.SUMMARY fields with custom RecordSummaryFunctions.

    If the user types data into the grid the RecordSummaryFunctions operate as expected. But if I programmatically set new data in the grid via setData() the RecordSummaryFunctions are not called. Double-clicking a row to start editing triggers the calculation. How do I programmatically trigger the summary function for each record after calling setData()?

    #2
    Thanks for pointing this out. This is now fixed (fix will show up in the next nightly build).

    Comment


      #3
      This was working but as of SmartClient Version: SC_SNAPSHOT-2011-03-24/PowerEdition Deployment (built 2011-03-24) it no longer works. The Record summaries are not calculated by the call to setData(), but if any one row is subsequently edited all rows have their Record summary fields recalculated.
      Last edited by jay.l.fisher; 28 Mar 2011, 13:52.

      Comment


        #4
        Looks like this was an issue for grouped grids only. Should be fixed in the next nightly build.

        Comment


          #5
          SmartClient Version: SC_SNAPSHOT-2011-04-22/PowerEdition Deployment (built 2011-04-22)
          This is still not happening. Although grouping is allowed the grid is not actually grouped during my tests. The only difference now is that, in order to trigger the recalculation of summary fields, I actually have to make a change to a grid row manually. Just double-clicking to start editing a row doesn't do it.
          Last edited by jay.l.fisher; 26 Apr 2011, 05:27.

          Comment


            #6
            This appears to be working in our tests - here's our simple test case.
            Code:
            public class RecordSummaryTest implements EntryPoint {
            
                ListGrid testGrid;
                ListGridRecord[] testData = new ListGridRecord[] {
                        new ListGridRecord() {{
                            setAttribute("f1", 1);
                        }},
                        new ListGridRecord() {{
                            setAttribute("f1", 56);
                        }},
                        new ListGridRecord() {{
                            setAttribute("f1", 210);
                        }}
                };
                @Override
                public void onModuleLoad() {
                    
                    ListGridField f1 = new ListGridField("f1");
                    f1.setType(ListGridFieldType.INTEGER);
                    
                    ListGridField summary = new ListGridField("summary");
                    summary.setType(ListGridFieldType.SUMMARY);
                    summary.setRecordSummaryFunction(new RecordSummaryFunction() {
                        
                        @Override
                        public Object getSummaryValue(Record record, ListGridField[] fields,
                                ListGridField summaryField) {
                            if (record == null) return null;
                            return "" + (record.getAttributeAsInt("f1") * 1000);
                        }
                    });
                    
                    testGrid = new ListGrid();
                    testGrid.setFields(f1,summary);
                    testGrid.setWidth(400);
                    testGrid.setHeight(200);
                    testGrid.draw();
                    
                    Button setData = new Button("Set Data");
                    setData.setLeft(500);
                    setData.addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                            testGrid.setData(testData);
                        }
                    });
                    setData.draw();
                }
            
            }
            Assuming the above works for you, there must be something else going on in your use case. If you could put together a simple standalone example similar to the one above that demonstrates the problem that'd probably be the quickest way for us to see what the problem is.

            Comment


              #7
              I had a similar issue with the custom summary functions not being called when the summary ListGridField are made visible (after the grid is already drawn).

              Comment


                #8
                My use case is actually updating data after the grid has been loaded initially. Originally I was using getDataAsRecordList(), iterating over the records and using setAttribute() to update fields in each record, then using setData() to "put the data back in the grid". I then switched to just using setAttribute() to update records in the RecordList followed by a call to ListGrid.markForRedraw(). That was working, but then stopped when I upgraded to April 22nd nightly build.

                I've modified your test case to do the same and it works. But my grid doesn't and I can't see what the difference is between the two. The workaround I'm using for now is to replace markForRedraw() with this.
                Code:
                for (Record record : records.toArray()) {
                	grid.updateData(record);
                	break;
                }
                That 'dummy' updateData() on the first grid record triggers a complete recalc for all records and a redraw of the grid to show the new summaries. Here is what I've done with your test case to make it as similar to mine as possible. Like I said, it's working and my grid is not. I'll keep trying to see what it is that causes it to not work, but if you have any clues based on this please let me know.
                Code:
                public class BuiltInDS implements EntryPoint {
                
                    ListGrid testGrid;
                
                    @Override
                    public void onModuleLoad() {
                        
                        ListGridField f1 = new ListGridField("f1");
                        f1.setType(ListGridFieldType.INTEGER);
                        
                        ListGridField summary = new ListGridField("summary");
                        summary.setType(ListGridFieldType.SUMMARY);
                        summary.setIncludeInRecordSummary(false);
                        summary.setRecordSummaryFunction(new RecordSummaryFunction() {
                            
                            @Override
                            public Object getSummaryValue(Record record, ListGridField[] fields,
                                    ListGridField summaryField) {
                                if (record == null) return null;
                                return "" + (record.getAttributeAsInt("f1") * 1000);
                            }
                        });
                        
                        testGrid = new ListGrid();
                        testGrid.setDataSource(DataSource.get("animals"));
                        testGrid.setAutoFitData(Autofit.HORIZONTAL);
                        testGrid.setCanEdit(true);
                        testGrid.setShowGridSummary(true);
                        testGrid.setShowGroupSummary(true);
                        testGrid.setAutoFetchData(false);
                        testGrid.setSaveLocally(true);
                        testGrid.setSaveByCell(true);
                        testGrid.setFields(f1,summary);
                        testGrid.setWidth(400);
                        testGrid.setHeight(200);
                        testGrid.draw();
                        
                        Button setData = new Button("Set Data");
                        setData.setLeft(500);
                        setData.addClickHandler(new ClickHandler() {
                            
                            @Override
                            public void onClick(ClickEvent event) {
                                testGrid.setData(getData());
                            }
                        });
                        setData.draw();
                        
                        Button updateData = new Button("Update Data");
                        updateData.setLeft(600);
                        updateData.addClickHandler(new ClickHandler() {
                            
                            @Override
                            public void onClick(ClickEvent event) {
                                updateData();
                                testGrid.markForRedraw();
                            }
                        });
                        updateData.draw();
                    }
                    private RecordList getData() {
                    	RecordList data = new RecordList();
                    	data.add(new ListGridRecord() {{setAttribute("f1", 1);}});
                    	data.add(new ListGridRecord() {{setAttribute("f1", 56);}});
                    	data.add(new ListGridRecord() {{setAttribute("f1", 210);}});
                    	return data;
                    }
                    private void updateData() {
                    	RecordList data = testGrid.getDataAsRecordList();
                    	data.get(0).setAttribute("f1", 2);
                    	data.get(1).setAttribute("f1", 112);
                    	data.get(2).setAttribute("f1", 420);
                    }
                }

                Comment


                  #9
                  Not sure what the difference between this sample and your live app would be (Do you get any helpful warnings in the logs or anything?)

                  Regardless -- an approach which should work reliably would be to call "RecordList.set(index, record)", passing in your updated record. This essentially notifies the grid that the client-side data has changed, which will cause it to recalculate summaries, and redraw.

                  Comment

                  Working...
                  X