Announcement

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

    ListGrid.groupBy behaves differently if group value is null (bug?)

    I've done by best to isolate this test case in "v9.1p_2015-02-07/Pro Deployment", Chrome 40.0.2214.111 (64-bit). Here's the procedure:
    1) Click "Add Geometry". You'll see that a new row appears in the ListGrid right away with Geom initialized to Option1.
    2) In the Window that appears, change Geom from Option1 to Option2.
    3) Click "Save". If you watch the ListGrid, you'll see that it flickers from displaying "Option2" but then goes back to "Option1". Calling getCacheData tells me the value was set correctly, it's just not being displayed correctly.
    4) Redo procedure, this time typing something into the Rid option (i.e. giving the record a group value). This time, Option2 remains in the ListGrid display.

    Summary: there's something about the groupBy operation that's resulting in an erroneous display if the group's value is null.

    For my purposes, I'm going to add a validation to prevent null values from being saved regardless. Nevertheless, if you agree this is a bug then here's a test case for you.

    I could also fix it by calling invalidateCache.

    Code:
    var data = {
       data: [],
       "fields": [
          {
             "hidden": true, 
             "name": "id", 
             "primaryKey": true
          }, 
          {
             "type": "text", 
             "name": "rid"
          }, 
          {
             "valueMap": [
                "Option1", 
                "Option2"
             ], 
             "type": "enum", 
             "name": "geom"
          }
       ]
    };
    
    function makeGeometryEditor(grid,id){
       var rowNum = grid.getRecordIndex({"id":id});
       var record = grid.getRecord(rowNum);
       return isc.VLayout.create({
          membersMargin: 10,
          width:"100%",
          members:[
             isc.DynamicForm.create({
                width: "100%",
                numCols:4,
                dataSource: grid.dataSource,
                values: record,
                fields: data.fields
             }),
             isc.HLayout.create({
                height: 40,
                width: "100%",
                members:[
                   isc.LayoutSpacer.create(),
                   isc.Button.create({
                      title: "Save",
                      click: function(){
                         var form = this.parentElement.parentElement.children[0];
                         var values = form.getValues();
                         rowNum = grid.getRecordIndex({"id":id});
                         grid.setEditValues(rowNum,values);
                         grid.saveAllEdits();
                         //Commenting this line makes it work:
                         grid.groupBy(["rid"]);
                         //Uncommenting this line makes it work:
                         //grid.invalidateCache();
                      }
                   }),
                   isc.LayoutSpacer.create()
                ]
             })
          ]
       });
    }
    
    isc.ClassFactory.defineClass("GeometryItem", "CanvasItem");
    isc.GeometryItem.addProperties({
       shouldSaveValue:true,
       createCanvas: function() {
          var initial = this.getValue();
          var lg = isc.ListGrid.create({
             dataSource: isc.DataSource.create({
                clientOnly:true,
                cacheData:initial.data,
                fields:initial.fields
             }),
             autoFetchData:true,
             groupByField: ["rid"],
             fields: [{"name":"rid",hidden:true},
                      {"name":"editor","title":"Editor"},
                      {"name":"geom"}
                     ],
             groupStartOpen:"all",
    
             showRecordComponents: true,
             showRecordComponentsByCell: true,
             recordComponentPoolingMode: "data",
    
             createRecordComponent : function (record, colNum) {  
                var fieldName = this.getFieldName(colNum);
                if (fieldName == "editor") {  
                   var recordCanvas = isc.HLayout.create({
                      height: 22,
                      width: "100%",
                      align: "center"
                   });
    
                   var editImg = isc.ImgButton.create({
                      showDown: false,
                      showRollOver: false,
                      layoutAlign: "center",
                      src: "icons/16/comment_edit.png",
                      prompt: "Edit Geometry",
                      height: 16,
                      width: 16,
                      grid: this,
                      click : function () {
                         var editor = isc.Window.create({
                            autoDraw: true,
                            isModal: true,
                            showModalMask: true,
                            autoSize: true,
                            autoCenter: true,
                            title:"Geometry Editor",
                            grid: this.grid,
                            items:[
                               makeGeometryEditor(this.grid,record["id"])
                            ]
                         });
                      }
                   });
                   if(!("rid" in record) || record["rid"] == null){
                      editImg.click();
                   }
                   recordCanvas.addMember(editImg);  
                   return recordCanvas;  
                } else {
                   return null;  
                }
             },
          });
    
          var add = isc.Button.create({
             title: "Add Geometry",
             lastID: null,
             click: function(){
                var id = this.lastID;
                if(id == null){
                   for(var i=0; i<data.data.length; i++){
                      if(id == null || data.data[i].id > id){
                         id = data.data[i].id;
                      }
                   }
                }
                id = id+1;
                this.lastID = id;
                data.data.push({id:id,geom:"Option1",atoms:[],period:"360"});
                lg.invalidateCache();
             }
          });
    
          return isc.VLayout.create({
             height:"100%",
             width:"100%",
             members:[lg,add]
          });
       },
       showValue : function (displayValue, dataValue) {
          if (this.canvas == null) return;
          var lg = this.canvas.members[0];
          lg.dataSource.setCacheData(dataValue.data);
          lg.invalidateCache();
          this.canvas.show();
       }
    });
    
    var df = isc.DynamicForm.create({
       width:300,
       height:200,
       autoDraw:true,
       numCols:1,
       colWidths:["*"],
       fields:[{name:"cgbf",showTitle:false,editorType:"GeometryItem",defaultValue:data}]
    });

    #2
    We are able to reproduce the problem and are looking into this issue.

    In the meantime, as a workaround, you can alter your button click handler to call groupBy() in a callback function provided to saveAllEdits(), as documented here: http://www.smartclient.com/docs/10.0...d.saveAllEdits. This will ensure groupBy() runs after saveAllEdits() is complete, leaving the grid in a consistent state.

    Comment


      #3
      Thanks for pointing this out. We've fixed the issue going back to SGWT 4.1p. The fixed nightly builds will be available tomorrow.

      Comment

      Working...
      X