How can I detect when I undo changes made in Paste?

Posted by: shuhei.suzuki on 4 August 2020, 9:41 pm EST

    • Post Options:
    • Link

    Posted 4 August 2020, 9:41 pm EST

    ValueChanged events were not executed when undoing after changing the value of a cell in a paste.

    How can this be detected?

    The system requires the values to be stored in RDS when the value in a cell is changed.

    So we want to detect the changes.

    Sample implemented in VueJS

    HTML

    
    <gc-spread-sheets
      @rangeChanged="rangeChanged"
      @valueChanged="valueChanged"
      @clipboardPasted="clipboardPasted">
    ...
    </gc-spread-sheets>
    
    

    JavaScript

    
    valueChanged: function (_, values) {
      values.newValue = (values.newValue === null) ? undefined : values.newValue
      // If the value is not allowed, revert to the previous value
      if (values.newValue !== undefined && !String(values.newValue).match(/^([1-9]\d*|0)(\.\d+)?$/)) {
        this.dataSource[values.row][key] = values.oldValue
        return
      }
      this.$emit('updateValue', {
        numberOfPeople: values.newValue,
      })
    },
    
    rangeChanged(_, args) {
      // Processed only when clear
      if (args.action !== 2) {
        return
      }
      args.changedCells.forEach((cells) => {
        const values = {
          col: cells.col,
          row: cells.row,
          newValue: undefined
        }
        this.valueChanged(null, values)
      })
    },
    
    clipboardPasted(_, args) {
      let data = []
      const range = args.cellRange
      // Convert pasted text into an array
      let rowText = args.pasteData.text.split('\n')
      for (let i = 0; i < rowText.length; i++) {
        data[i] = []
        let rowValues = rowText[i].split('\t')
        for (let j = 0; j < rowValues.length; j++) {
          data[i].push(rowValues[j].trim())
        }
      }
      ...
      this.valueChanged(null, values)
    }
    
    
  • Posted 5 August 2020, 10:24 am EST

    Hi,

    In SJS 13.2.0 RangeChanged Events args has the property isUndo which can be used to detect the changes by undo operation. Please refer to the following code snippet and let us know if you face any issues.

    spread.bind(GC.Spread.Sheets.Events.RangeChanged, function(e, info) {
              if(info.isUndo){
                console.log("RangeChanged By Undo");
              }
            });
    
    

    Also for detecting chages via paste you may use RangeChangedAction enum. Please Refer to following code snippet.

    spread.bind(GC.Spread.Sheets.Events.RangeChanged, function(e, info) {
              if(info..action ===    GC.Spread.Sheets.RangeChangedAction.paste){
                console.log("RangeChanged By Paste");
              }
            });
    

    API References:

    • RangeChanged: https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.Events~RangeChanged_EV.html

    • RangeChangedAction: https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.RangeChangedAction.html

    Regards

  • Posted 6 August 2020, 12:31 am EST

    It worked as expected.

    Thank you very much!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels