NEW VERSION RELEASED! Webix 11 Read More Core Updates, Extended Functionalities in SpreadSheet and File Manager and more

Custom Clipboard Operations with DataTree, JavaScript Programming Example of Custom Clipboard Operations with DataTree

JavaScript Programming Example of Custom Clipboard Operations with DataTree

Try our sample code for custom clipboard operations with DataTree. This piece of code shows the behavior of the "customized" clipboard which allows users to specify a custom logic for the inserting data. See how it works: 1) When you press Ctrl+C, the data gets to the clipboard. 2) When you press Ctrl+V, DataTree invokes the onPaste event. You can handle this event to set a custom logic. By default, the handler doesn't do anything. Press CTRL+C to copy an item from the textarea. Then, select some node in DataTree and press Ctrl+V (note, in the current sample the onPaste handler just alerts messages and doesn't change DataTree items). We kindly invite you to use our coding samples for building your web applications.

JS Code

/*
  You can implement custom clipboard logic. 
  Press Ctrl+C to copy an item from the textarea. 
  
  Then select some node in Tree and press Ctrl+V (note, in the current sample the onPaste handler just alerts messages and doesn't change Tree items).
*/


webix.ui({
  rows:[
    { height:200, type:"clean",
     cols:[
       {	
         view:"tree",
         id:"tree1",
         width:300,
         select: true,
         clipboard: "custom",
         data: [
           { id:"1", open:true, value:"The Shawshank Redemption", data:[
             { id:"1.1", value:"Part 1" },
             { id:"1.2", value:"Part 2" },
             { id:"1.3", value:"Part 3" }
           ]},
           { id:"2", value:"The Godfather", data:[
             { id:"2.1", value:"Part 1" },
             { id:"2.2", value:"Part 2" }
           ]}
         ]
       },
       {view:"textarea", value:"New tree item", width:300}
     ]}
  ]
});	

$$("tree1").attachEvent("onPaste", function(text) {
  webix.message("Node is pasted: " + text);
});