Multi deleteRows

Posted by: 122368177 on 9 May 2020, 3:29 am EST

  • Posted 9 May 2020, 3:29 am EST

    hi,

    I would like to delete selected multi rows.

    I loop to deleteRows(row,rowCount),

    
    selections.forEach((selection) => {
          const { row, rowCount } = selection
          sheet.deleteRows(row, rowCount)
        })
    
    

    but I didn’t get the results I wanted.

    1,2,3,4,5,6

    I want delete row 1,3,it deleted row1,4.

    I kown sheet draw by steps,but …I have no idea~

    Thanks

  • Posted 12 May 2020, 8:10 am EST

    Hi,

    For deleting the row from the multiple selections you need to sort the selections array on the basis of row index, currently, the issue is arising because when we delete the first selection other selections are shifted to the top. Please refer to the following code snippet and sample which demonstrate the same:

    selections.sort((sel, sel2) => {

    return sel.row < sel2.row ? 1 : -1;

    });

    selections.forEach(selection => {

    sheet.deleteRows(selection.row, selection.rowCount);

    });

    sample: https://codesandbox.io/s/quirky-jennings-mnv5s

    Regards

Need extra support?

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

Learn More

Forum Channels