Announcement

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

    #16
    Right - but just to clarify, a saveData() call is always asynchronous even with a clientOnly DataSource. So you'll want to saveData(), wait for the callback, and then call collapseRecord() (assuming success - you don't want to proceed with the collapse if there are, eg, validation errors).

    Did you say you already tried that? Can you show the code for that attempt?

    You also mentioned the grid being "frozen" - how so? Is your code in the callback for saveData() executing? If so, is the grid frozen before or after you attempt to call collapseRecord() from the callback?

    Comment


      #17
      I moved the call to collapseRecord() into a callback and I can see that it is executing. The grid isn't frozen, but the row is not collapsing either. The row expand/collapse icon moves back into the collapsed position but the expansion area beneath the row remains visible. Here's the revised collapse code.
      Code:
      myGrid.addRecordCollapseHandler(new RecordCollapseHandler() {				
      	@Override
      	public void onRecordCollapse(RecordCollapseEvent event) {
      		event.cancel();
      		final ListGridRecord record = (ListGridRecord) event.getRecord();
      		DynamicForm df = new DynamicForm(Canvas.getById(record.getAttribute("formID")).getJsObj());
      		df.saveData(new DSCallback() {
      			@Override
      			public void execute(DSResponse response, Object rawData, DSRequest request) {
      				myGrid.collapseRecord(record);
      			}
      		});
      	}
      });

      Comment


        #18
        The issue appears to be that when you call collapseRecord explicitly, you're collapse handler is firing again and attempting to cancel the collapse again.
        This is basically as expected - the collapse handler does fire whether the collapse came form user interaction or programmatic call to collapseRecord - but we shouldn't be getting into the bad state with the expand/collapse icon updating without the record collapsing.
        We'll look into that particular aspect of this issue.

        However adding a check to see if the user has edited the data, and only cancelling collapse / kicking off a save if they have (and if we're not already saving) should resolve this:
        Code:
                myGrid.addRecordCollapseHandler(new RecordCollapseHandler() {               
                    @Override
                    public void onRecordCollapse(RecordCollapseEvent event) {
                        final ListGridRecord record = (ListGridRecord) event.getRecord();
                        DynamicForm df = (DynamicForm)Canvas.getById(record.getAttribute("formID"));
                        if (df.valuesHaveChanged()) {
                            // rememberValues so when this method runs again from the save completing, the record
                            // successfully collapses.
                            df.rememberValues();
                            event.cancel();
                            df.saveData(new DSCallback() {
                                    @Override
                                    public void execute(DSResponse response, Object rawData, DSRequest req) {
                                        myGrid.collapseRecord(record);
                                    }
                                },
                                // Show a prompt to avoid having the user hammering away at the 
                                // collapse icon during the save
                                new DSRequest () {{
                                    setShowPrompt(true);
                                    setPromptStyle(PromptStyle.CURSOR);
                                }}
                            );
                        }
                    }
                });
        Note: I got a bit fancy and made sure a blocking prompt was shown during save so the user couldn't hit the collapse icon again, or further edit values while save was in process.

        Let us know if this gets things working for you.

        Comment


          #19
          Thanks. That worked. But would you consider making that the default behavior for ListGrid.setExpansionMode(ExpansionMode.EDITOR) in the future. I can't see much use for ExpansionMode.EDITOR otherwise.

          Comment

          Working...
          X