Edit multiple cells at once with custom made logic

Posted by: bogdan.raicu on 27 June 2022, 5:42 am EST

  • Posted 27 June 2022, 5:42 am EST

    (For some reason, this post is marked as spam, so I’ll just try adding this text here)

    Hello!

    This is a follow-up ticket for another situation I discussed with you some time ago: https://www.grapecity.com/my-account/my-support/case/CAS-31771-C0V2G9

    A little summary about our functionality: we enhanced the user input by offering input acceleration ( the cell value of 1k will return 1 000, the value 1m will return 1 000 000, the value 50% will return 50% of that number etc .) and incremental data change ( 5000+ will return current cell value plus 5000, 3* will return three times the cell value etc. )

    We would like to know if we can apply this kind of functionality to a range of cells (either selected by dragging from one cell to another or by ctrl + click) i.e. if I add 500+ to a range of cells, i want 500 to be added to the current cell value of each cell that is part of my range.

    Thanks for your support!

  • Posted 28 June 2022, 12:03 am EST

    Hi,

    For this, you need to implement a custom command and execute the command whenever you want such as drop event add an event for ctrl+click. Please refer to the following demo that explains the custom command and let me know if you face any issues.

    
     ss.getHost().addEventListener("mousedown",(e)=>{
    if(e.ctrlKey){
    let sheet = ss.getActiveSheet();
    let selection = sheet.getSelections()}}
    /*You may now traverse the selection and change the value of the sheet or call the custom action here*/
    
    /* for changing the drag*/
    
    ss.getActiveSheet().bind("DragFillBlockCompleted",(e,args)=>
    {
       console.log(e,args);
    /*change the args.fillRange according to your need.*/
    })
    ,true);
    
    

    customAction: https://www.grapecity.com/spreadjs/demos/features/worksheet/actions/custom-action#demo_source_name

    DragFillBlockCompleted: https://www.grapecity.com/spreadjs/docs/latest/online/SpreadJS~GC.Spread.Sheets.Events~DragFillBlockCompleted_EV.html

    Regards,

    Avinash

  • Posted 1 July 2022, 7:08 am EST

    In the end we managed, to achieve this with the following structure. Thanks for your help!

      reference.bind(GC.Spread.Sheets.Events.EditEnded, (event: any, data: GC.Spread.Sheets.IEditEndedEventArgs) => {
        const { isDirty } = getState().notification;
        if (!isDirty) {
          dispatch(setWorkbookIsDirty(true));
        }
    
        const inputValue = data.editingText;
        const selections = data.sheet.getSelections();
        const oldValue = getState().workbook.prevCellValue;
        const { sheet } = data;
    
        for (let i = 0; i < selections.length; i++) {
          const selection = selections[i];
          const { row, rowCount, col, colCount } = selection;
    
          for (let currentRow = row; currentRow < rowCount + row; currentRow++) {
            for (let currentCol = col; currentCol < colCount + col; currentCol++) {
              const isEditedCell = data.col === currentCol && data.row === currentRow;
              const prevValue = isEditedCell ? oldValue : sheet.getValue(currentRow, currentCol);
              const calculatedValue = checkInputEnhancement(prevValue, inputValue);
              sheet.setValue(currentRow, currentCol, calculatedValue);
            }
          }
        }
      });
    
  • Posted 4 July 2022, 7:27 am EST

    Hi,

    We are glad to know that the issue has been resolved. Thanks for sharing the solution with us.

    Regards,

    Avinash

Need extra support?

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

Learn More

Forum Channels