Announcement

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

    modify droppedRecord field onRecordDrop

    Version v9.1p_2014-03-03/Enterprise Deployment (2013-03-03)

    I'm trying to regroup a listgrid record when the user drags it into a new group (same listGrid), based on a "Custom Group" column.
    As the user drops the record, its Custom Group value should change to match that of the record above it, followed by a redraw to take care of the rest.

    I'm having trouble getting the correct index/rowNum to use setEditValue or refreshCell though - the 'index' parameter in onRecordDrop does not apply to the droppedRecord & using getRecordIndex just returns -1, record not found.

    The following snippet is slightly modified (and broken) version of http://www.smartclient.com/docs/9.0/a/system/reference/SmartClient_Explorer.html#listGridFields.

    Code:
    isc.ListGrid.create({
       canReorderRecords: true,
        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,
        onRecordDrop: function(droppedRecord, targetRecord, index) {
    //insert logic to get appropriate value to update field here...
    
          this.setEditValue(index, "countryCode", "newValue");
          this.markForRedraw();
      }
    })
    Keeping this in mind, how would I go about changing a column value of droppedRecord, or am I going about this the wrong way?

    #2
    At the moment of a drop, getEventRow() can be used to get the row under the mouse.

    Note that getRecordIndex() should be returning -1 because the data being dropped has not been added to the grid's data set yet.

    Comment


      #3
      Thanks for the quick reply, but I think your explanation for why getRecordIndex returns -1 counts for getEventRow too & would also explain why simply adding or subtracting 1 from the supplied index won't work either.
      Using getEventRow with setEditValue modifies the row you are dropping the record on, not the actual record being dropped.
      I've expanded the previous example to demonstrate my issue:

      Code:
      isc.ListGrid.create({
         canReorderRecords: true,
          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"},
              {name:"CUSTOM", title:"Custom Group"}
          ],
          data: countryData,
         onRecordDrop: function(droppedRecord, targetRecord, index) {
                         var groupByThisRecord = 0;                        
                          var droppedRecordRow = this.getEventRow();
      //GET THE RECORD ABOVE, UNLESS YOU'RE DROPPING THIS AT THE TOP OF THE LIST                
                          if (index != 0) {
                              groupByThisRecord = this.getRecord(index-1);
                          } else groupByThisRecord = this.getRecord(index);
      
                          if (groupByThisRecord.CUSTOM === undefined) {     
                              this.setEditValue(droppedRecordRow, "CUSTOM", index);
                          } else {                       
                              this.setEditValue(droppedRecordRow, "CUSTOM", groupByThisRecord.CUSTOM);
                          }
                          this.markForRedraw();
      }
      })
      I've also tried editing the droppedRecord (droppedRecord.fieldName = newValue) as per your example on http://www.smartclient.com/docs/9.0/...ListGridRecord, but once again I need a valid row to apply the change with ListGrid.refreshCell(), which brings me back to square one.
      Last edited by stav; 26 Mar 2014, 01:13. Reason: modify code snippet

      Comment


        #4
        getEventRow() is based on the mouse position so is not affected by the drop data at all.

        Could you explain what record it is that you are trying to find? If what you want is just the group node, that's very simple - access the listGrid.groupTree and find the parent of the current row as returned by getEventRow().

        Comment


          #5
          I want to programatically change the CUSTOM column value of the droppedRecord in the onRecordDrop function.

          This record is already available as the first parameter in the onRecordDrop function, so finding it is not the issue.

          Instead, I'm having a tough time applying a change to this droppedRecord & re-inserting it into the listGrid, as all methods (such as refreshCell & setEditValue) require a rowNum. Is there an "apply this change to the droppedRecord and redraw the listGrid" method that does not require a rowNum?

          Apologies if my previous posts didn't make this clear enough

          Comment


            #6
            If we're reading you correctly, you want to allow the record to be added to the local dataset and then apply at editValue.

            If so, what you should do is override recordDrop (not "onRecordDrop") and call Super(), which will actually transfer the data so you will be able to find the new record in this.data.

            Note that "onRecordDrop" is not actually a documented SmartClient API - it appeared erroneously in the documentation for some early builds, but this has been fixed for a while.

            Comment


              #7
              Thanks, that works perfectly!

              Comment

              Working...
              X