Announcement

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

    ListGrid selectionChanged event sent too many times

    A deselection event and a selection event are sent when a record already selected is double clicked for edit. The same happens when the record is in edit mode and the focus is changed to any edit control. In both cases selection events should not be sent as they trigger unnecessary updates in other sections of the screen. I modified a Feature Explorer sample to demonstrate the issue:

    Code:
    isc.ListGrid.create({
        ID: "countryList",
        width:550, height:224, alternateRecordStyles:true, showAllRecords:true, cellHeight:22,
        dataSource: countryDS,
        selCount: 0,
        deselCount: 0,
        fields:[
            {name:"countryCode", title:"Flag", width:40, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png", canEdit:false},
            {name:"countryName"},
            {name:"continent"},
            {name:"member_g8"},
            {name:"population", formatCellValue:"isc.Format.toUSString(value);"},
            {name:"independence"}
        ],
        autoFetchData: true,
        canEdit: true,
        editEvent: "doubleClick",
        modalEditing: true,
    
        selectionChanged: function(record, isSelected)
        {
            var ret = this.Super("selectionChanged", arguments);
    
           if( isSelected )
               this.selCount += 1;
           else
               this.deselCount += 1;
    
           selLabel.setContents('Selections: ' + this.selCount + ', Deselections: ' + this.deselCount);
    
           return ret;
        }
    })
    
    isc.Label.create({
        ID: "selLabel",
        top: 225,
        contents: "selections ..."
    });

    #2
    The post is quite old, but I had same problem recently. So my solution might be helpful for someone with the same issue. I overrode "selectRecordForEdit" method for TreeGrid:

    Code:
      selectRecordForEdit: function (_1) {
        if(!this.editByCell)
          _1.$29m=true;
        if(this.canSelectCells){
          var _2=this.getRecordCellIndex(_1);
          this.selection.selectSingleCell(_2[0],_2[1])
        }
        else if (this.selection != null && (!this.selection.isSelected(_1) || this.selection.multipleSelected())){
          if(this.selectionType==isc.Selection.NONE){
              this.logInfo("selectOnEdit is true, but this.selectionType is set to 'none'."+" Unable to perform a selection on edit.","gridEdit")
          }
          else if(this.selectionType==isc.Selection.SIMPLE)
            this.selection.select(_1);
          else {
            this.selection.selectSingle(_1)
          }
        }
        delete _1.$29m;
      }
    I just added condition to the first else:

    if (this.selection != null && (!this.selection.isSelected(_1) || this.selection.multipleSelected())

    Updated: here is the sample with fixed selectRecordOnEdit method (actually it's better to call Super)
    Code:
    isc.ListGrid.create({
        ID: "countryList",
        width:500, height:224, alternateRecordStyles:true, 
        fields:[
            {name:"countryCode", title:"Code"},
            {name:"countryName", title:"Country"},
            {name:"independence", title:"Nationhood", type:"date"},
            {name:"population", title:"Population", type:"integer"},
            {name:"gdp", title:"GDP", type:"float"}
        ],
        data: countryData,
        canEdit: true,
        editEvent: "doubleClick",
        modalEditing: true,
        selCount: 0,
        deselCount: 0,
        selectionChanged: function(record, isSelected)
        {
            var ret = this.Super("selectionChanged", arguments);
    
           if( isSelected )
               this.selCount += 1;
           else
               this.deselCount += 1;
    
           selLabel.setContents('Selections: ' + this.selCount + ', Deselections: ' + this.deselCount);
    
           return ret;
        },
      selectRecordForEdit: function (record) {
        if (!this.canSelectCells && this.selection != null && 
          this.selection.isSelected(record) && !this.selection.multipleSelected()) {
            return; // do not re-select
        }
        var args = new Array();
        args[0] = record;
        this.Super("selectRecordForEdit", args);
      }  
    })
    
    isc.Label.create({
        ID: "selLabel",
        top: 225,
        contents: "selections ..."
    });
    Last edited by ESherbakova; 15 Sep 2010, 10:03.

    Comment

    Working...
    X