Cut Rows

Is it possible to cut selected rows and paste?.


10 Replies

TS Thiyagu Subramani Syncfusion Team October 12, 2021 02:09 AM UTC

Hi Chris, 

Thanks for contacting Syncfusion support. 

We have achieved cut operation (Ctrl + x) in sample level using keydown and beforePaste event. When pressing CTRL + X, we have copied selected cell (select complete row by selection each cell) value to the clipboard by calling copy method and using beforePaste event we have cleared value to that required cell using updateCell method. Please refer to the below code and sample link. 

created(args){ 
        document.addEventListener('keydown', function (e) { 
            if (e.keyCode === 88) { 
                this.flag = true; 
                for (var i = 0; i < this.grid.getSelectedRowCellIndexes()[0].cellIndexes.length; i++) { 
                    this.fieldData.push(this.grid.getColumnByIndex(this.grid.getSelectedRowCellIndexes()[0].cellIndexes[i]).field); 
                } 
                this.cutIndex = this.grid.getSelectedRowCellIndexes(); 
                this.grid.copy(); 
            } 
        }.bind(this)); 
    } 

    beforePaste(args) { 
        if (this.flag == true) { 
            for (var i = 0; i < this.cutIndex.length; i++) { 
                var rowInfo = this.grid.getRowInfo(this.grid.getRowByIndex(this.cutIndex[i].rowIndex)) 
                for (var j = 0; j < this.fieldData.length; j++) { 
                    if (rowInfo.rowData[this.fieldData[j]] != '') { 
                        this.grid.updateCell(this.cutIndex[i].rowIndex, this.fieldData[j], ''); 
                    } 
                } 
            } 
        } 
    } 


Please get back to us, if you need any further assistance. 

Regards, 
Thiyagu S 




CJ Chris Johnson October 14, 2021 07:11 AM UTC

Thank you so much.  Yes, this what I expected, now need to place it in contextmenu Cut and Paste; will get you back if we need any help from your side.



Regards,

Chris Johnson



TS Thiyagu Subramani Syncfusion Team October 15, 2021 03:50 AM UTC

Hi Chris, 

Thanks for the update. 

We are happy to hear that the provided solution works at your end and please contact us if you need any further assistance. As always, we will be happy to assist you.    
   
Regards,  
Thiyagu S 



CJ Chris Johnson October 17, 2021 06:24 AM UTC

Hi Thiyagu,


I have one more doubt, the sample which you have done is in normal grid right?, suppose in case if we need implement in to treegrid, what changes should be made to this? can you please suggest?.


Thanks and regards,

Chris Johnson



CJ Chris Johnson replied to Chris Johnson October 18, 2021 02:04 PM UTC

Hi Thiyagu,


Can I get a response please or should I open a new ticket?.


Thanks and regards,

Chris Johnson



TS Thiyagu Subramani Syncfusion Team October 18, 2021 02:32 PM UTC

Hi Chris,

 
Thanks for your update and sorry for the delay. 

Based on the queries we have prepared a sample for cut/paste in TreeGrid, please find the sample below.

Sample link: https://stackblitz.com/edit/angular-i345491-cutpaste?file=app.component.ts

Regards,
Thiyagu S 



CJ Chris Johnson October 24, 2021 06:06 AM UTC

Hi Thiyagu,


We have minor query, you have give the solution so as we can use ctrl+X for cut and ctrl+V for paste, its perfect.  Now we tried to implement Cut and Copy function in context menu, we succeeded with Paste, but couldnt get a proper output for Cut.  When clicking ctrl+X and clicking Paste it works.  Can you help us out.


Thanks and regards,

Chris Johnson



BS Balaji Sekar Syncfusion Team October 25, 2021 05:12 PM UTC

Hi Chris, 

Currently we are working your query with shared information and we will update further details on October 26, 2021 

Until then we appreciate your valuable patience. 

Regards, 
Balaji Sekar. 



CJ Chris Johnson October 26, 2021 04:32 AM UTC

Hi Balaji,


Alright.  No issues, will wait.  Thanks for your update.


Thanks and regards,

Chris Johnson



BS Balaji Sekar Syncfusion Team October 26, 2021 08:40 AM UTC

Hi Chris, 

Thanks for your update. 

We have implemented the Cut functionality in context menu using contextMenuClick event. In this event, we have copied the respective cell value when click on copy item from ContextMenu once paste on target cell it will paste and remove the copied value from copied cell.  

Please refer the below code example and sample for more information. 

[app.component.ts] 
  contextMenuClick(args) { 
    if (args.item.text == 'Cut') { 
      this.flag = true; 
      for ( 
        var i = 0; 
        i < this.grid.getSelectedRowCellIndexes()[0].cellIndexes.length; 
        i++ 
      ) { 
        this.fieldData.push( 
          this.grid.getColumnByIndex( 
            this.grid.getSelectedRowCellIndexes()[0].cellIndexes[i] 
          ).field 
        ); 
      } 
      this.cutIndex = this.grid.getSelectedRowCellIndexes(); 
      this.grid.copy(); 
    } 
  } 


Please get back to us, if you need further assistance. 

Regards, 
Balaji Sekar 


Loader.
Up arrow icon