Announcement

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

    Suppress Can Remove Records - auto - for one record in set

    SmartClient Version: SNAPSHOT_v11.1d_2017-01-31/PowerEdition Deployment (built 2017-01-31)

    I want to suppress the auto removal of ONE particular record in a ListGrid, when calling saveAllEdits()

    I tried to add a addRemoveRecordClickHandler but it seems to suppress the remove of all records.

    final ListGrid techGrid = new ListGrid() ;
    techGrid.setDataSource("ISO_UIProjectTechnology");
    techGrid.setShowFilterEditor(true);
    techGrid.setAutoFitFieldWidths(true);
    techGrid.setAutoFitData(Autofit.BOTH);
    techGrid.setCanEdit(true);
    techGrid.setCanRemoveRecords(true);
    techGrid.setAutoFetchData(true);
    techGrid.setDeferRemoval(true);
    techGrid.setAutoFitMaxRecords(22);

    With just the above code, clicking the remove icon marks the record for removal and removes the record when the icon that controls 'saveAllEdits()' is clicked. All is well except I want to suppress the behavior for one record value.

    So I added this code:

    techGrid.addRemoveRecordClickHandler(new RemoveRecordClickHandler() {

    @Override
    public void onRemoveRecordClick(RemoveRecordClickEvent event) {
    int row = event.getRowNum();
    Record recRm = techGrid.getRecord(row);
    String rule = recRm.getAttributeAsString("TechDescription");
    if ( "generic".equalsIgnoreCase(rule)){
    SC.warn("No one may remove the <b><i>generic</i></b> Tech Rule Type");
    techGrid.unmarkRecordRemoved(row);
    }
    techGrid.markRecordRemoved(row);
    return;
    }
    } );

    Now clicking the remove icon on the row containing the value 'generic' gets a popup warning not allowing the remove. But clicking any other record a) does not mark the record for removal and b) does not cause the record to be removed when saveAllEdits() is called.

    Do I have to define a techGrid.removeData() function instead of the simple use of markRecordRemoved()? How can I retain the functionality of marking the records for delete and only executing the delete when saveAllEdits() is called?

    Thanks

    #2
    Bump

    Any comments out there?

    Comment


      #3
      Hi,
      Sorry for the delay on this - for some reason our internal notification system didn't pick it up. We're looking into that.
      Anyway, to answer the question - the reason this isn't working is a subtle one - you're explicitly marking the record as removed in the case where you want it removed, but failing to cancel the event (which means standard remove-click handling behvior proceeds). This standard behavior toggles the removed state of course (allowing users to remove/restore records). In this case it sees the record has been marked as removed (by your code), and toggles that back, so the record ends up not marked for removal.
      The right way to handle this is actually simpler - you need to cancel the event to suppress the default behavior in the case where you don't want the record removed:
      Code:
                      @Override
                      public void onRemoveRecordClick(RemoveRecordClickEvent event) {
                          int row = event.getRowNum();
                          Record recRm = techGrid.getRecord(row);
                          String rule = recRm.getAttributeAsString("TechDescription");
                          if ( "generic".equalsIgnoreCase(rule)){
                              SC.warn("No one may remove the <b><i>generic</i></b> Tech Rule Type");
                              event.cancel();
                          }
                      }

      Comment


        #4
        Your suggestion works perfectly. Thanks.

        I posted another question yesterday on another topic, but it too seems to be ignored. Just FYI.

        T

        Comment

        Working...
        X