Announcement

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

    dataChanged not called on grid.setData

    SmartClient Version: v10.0p_2015-07-16/Enterprise Development Only (built 2015-07-16)

    Chrome on OSX

    Usually I use to observe the dataChanged method to display totalRows for grids.
    But it seems that it isn't called when I do setData([]).
    Is it correct behavior? I think that in the past this was working.
    You could try this test case:
    Code:
    isc.ListGrid.create({
        ID: "countryList",
        width:500, height:300, alternateRecordStyles:true, top:30,
        dataSource: worldDS,
        fields:[
            {name:"countryCode", title:"Code", width:50},
            {name:"countryName", title:"Country"},
            {name:"capital", title:"Capital"},
            {name:"continent", title:"Continent"}
        ],
        autoFetchData: true,
        showFilterEditor: true,
    dataChanged:function(){
         isc.say('dataChanged')
    }
    })
    
    isc.IButton.create({
      title:'set data',
      click:function() {
        countryList.setData([])
      }
    })

    #2
    The is by design. DataChanged is a notification used for user-initiated or possibly user-initiated changes (such as filtering).

    When you are calling setData() to change the data, you don't need a notification that you just changed the data, so we don't fire one.

    Comment


      #3
      I see. Actually I was using the approach outlined in the #gridComponents showcase sample:
      Code:
      isc.ToolStrip.create({
          ID: "gridEditControls",
          width: "100%", height:24, 
          members: [
              isc.Label.create({
                  padding:5,
                  ID:"totalsLabel"
              }),
              isc.LayoutSpacer.create({ width:"*" }),
              isc.ToolStripButton.create({
                  icon: "[SKIN]/actions/edit.png",
                  prompt: "Edit selected record",
                  click: function () {
                      var record = countryList.getSelectedRecord();
                      if (record == null) return;
                      countryList.startEditing(countryList.data.indexOf(record));
                  }
              }),
              isc.ToolStripButton.create({
                  icon: "[SKIN]/actions/remove.png", 
                  prompt: "Remove selected record",
                  click: "countryList.removeSelectedData()"
              })
          ]
      });
      
      isc.ListGrid.create({
          ID: "countryList",
          width:500, height:300, alternateRecordStyles:true,
          dataSource: worldDS,
          fields:[
              {name:"countryCode", title:"Code", width:50},
              {name:"countryName", title:"Country"},
              {name:"capital", title:"Capital"},
              {name:"continent", title:"Continent"}
          ],
          autoFetchData: true,
          showFilterEditor: true,
          canEdit:true,
          editEvent:"none",
          gridComponents:["header", "filterEditor", "body", gridEditControls],
          dataChanged : function () {
              this.Super("dataChanged", arguments);
              var totalRows = this.data.getLength();
              if (totalRows > 0 && this.data.lengthIsKnown()) {
                  totalsLabel.setContents(totalRows + " Records");
              } else {
                  totalsLabel.setContents(" ");
              }
          }
      })
      is there available a different approach which works even when calling setData ? Is it correct () to explicitly call grid.changed after calling grid.setData ?

      Comment


        #4
        If you have logic that needs to run both when the user makes a change to the dataset, and when you explicitly do so, just call that logic from both the dataChanged() event and from where you call setData().

        Comment

        Working...
        X