Clipboard
21 Dec 202213 minutes to read
The clipboard provides an option to copy selected rows or cells data into the clipboard.
The following list of keyboard shortcuts is supported in the Tree Grid to copy selected rows or cells data into the clipboard.
Interaction keys | Description |
---|---|
Ctrl + C | Copy selected rows or cells data into clipboard. |
Ctrl + Shift + H | Copy selected rows or cells data with header into clipboard. |
@(Html.EJS().TreeGrid("Clipboard")
.DataSource((IEnumerable<object>)ViewBag.dataSource)
.SelectionSettings(select =>
{
select.Mode(SelectionMode.Row);
select.Type(SelectionType.Multiple);
})
.Columns(col =>
{
col.Field("TaskId").HeaderText("Task ID").Width(110).TextAlign(TextAlign.Right).Add();
col.Field("TaskName").HeaderText("Task Name").Width(210).Add();
col.Field("Duration").HeaderText("Duration").TextAlign(TextAlign.Right).Width(110).Add();
col.Field("Progress").HeaderText("Progress").TextAlign(TextAlign.Right).Width(90).Add();
}).ChildMapping("Children").TreeColumnIndex(1).Height(200).Render())
public IActionResult Index()
{
var treeData = TreeGridItems.GetTreeData();
ViewBag.datasource = treeData;
return View();
}
Copy to clipboard by external buttons
To copy selected rows or cells data into the clipboard with help of external buttons, you need to invoke the copy
method.
@Html.EJS().Button("Copy").Content("Copy").IsPrimary(true).Render()
@Html.EJS().Button("CopyHeader").Content("Copy With Header").IsPrimary(true).Render()
@(Html.EJS().TreeGrid("CopyBtn")
.DataSource((IEnumerable<object>)ViewBag.dataSource)
.SelectionSettings(select =>
{
select.Mode(SelectionMode.Row);
select.Type(SelectionType.Multiple);
})
.Columns(col =>
{
col.Field("TaskId").HeaderText("Task ID").Width(110).TextAlign(TextAlign.Right).Add();
col.Field("TaskName").HeaderText("Task Name").Width(210).Add();
col.Field("Duration").HeaderText("Duration").TextAlign(TextAlign.Right).Width(110).Add();
col.Field("Progress").HeaderText("Progress").TextAlign(TextAlign.Right).Width(90).Add();
}).ChildMapping("Children").TreeColumnIndex(1).Height(200).Render())
<script>
document.getElementById("Copy").onclick = function () {
var treegrid = document.getElementById("CopyBtn").ej2_instances[0];
treegrid.copy();
}
document.getElementById("CopyHeader").onclick = function () {
var treegrid = document.getElementById("CopyBtn").ej2_instances[0];
treegrid.copy(true);
}
</script>
public IActionResult Index()
{
var treeData = TreeGridItems.GetTreeData();
ViewBag.datasource = treeData;
return View();
}
Copy Hierarchy Modes
Tree Grid provides support for a set of copy modes with CopyHierarchyMode
property.
The below are the type of copy mode available in TreeGrid.
-
Parent : This is the default copy hierarchy mode in Tree Grid. Clipboard value have the selected records with its parent records, if the selected records not have any parent record then the selected record will be in clipboard.
-
Child : Clipboard value will have the selected records with its child record. If the selected records do not have any child record then the selected records will be in clipboard.
-
Both : Clipboard value will have the selected records with its both parent and child record. If the selected records do not have any parent and child record then the selected records alone in clipboard.
-
None : Only the Selected records will be in clipboard.
@{
List<object> toolbar = new List<object>();
toolbar.Add(new { text = "Copy", tooltipText = "Copy", prefixIcon = "e-copy", id = "copy" });
toolbar.Add(new { text = "Copy With Header", tooltipText = "Copy With Header", prefixIcon = "e-copy", id = "copyHeader" });
}
@Html.EJS().DropDownList("SearchMode").Width("50%").DataSource((IEnumerable<object>)ViewBag.dropdata).Value("Parent").Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings { Text = "id", Value = "mode" }).Change("onChange").Render()
@(Html.EJS().TreeGrid("TreeGrid")
.DataSource((IEnumerable<object>)ViewBag.datasource)
.AllowPaging()
.Toolbar(toolbar)
.ToolbarClick("toolbarClick")
.SelectionSettings(sel =>
{
sel.Type(SelectionType.Multiple);
})
.PageSettings(p => p.PageSize(10))
.AllowSelection()
.Columns(col =>
{
col.Field("TaskId").HeaderText("Task ID").Width(80).TextAlign(TextAlign.Right).Add();
col.Field("TaskName").HeaderText("Task Name").Width(200).Add();
col.Field("StartDate").HeaderText("Start Date").Format("yMd").TextAlign(TextAlign.Right).Width(100).Add();
col.Field("Duration").HeaderText("Duration").TextAlign(TextAlign.Right).Width(90).Add();
col.Field("Progress").HeaderText("Progress").TextAlign(TextAlign.Right).Width(90).Add();
}).ChildMapping("Children").TreeColumnIndex(1).Render())
<script>
function toolbarClick(args) {
if (this.getSelectedRecords().length > 0) {
var withHeader = false;
if (args.item.id === 'copyHeader') {
withHeader = true;
}
this.copy(withHeader);
} else {
var dialogObj = document.getElementById('alert_dialog').ej2_instances[0];
dialogObj.show();
}
}
function onChange(e) {
var mode = e.value;
var treegrid = document.getElementById("TreeGrid").ej2_instances[0];
treegrid.copyHierarchyMode = mode;
}
</script>
public IActionResult Index()
{
var treeData = TreeGridItems.GetTreeData();
ViewBag.datasource = treeData;
List<Object> dropData = new List<object>() {
new { id = "Parent", mode = "Parent" },
new { id = "Child", mode = "Child" },
new { id = "Both", mode = "Both" },
new { id = "None", mode = "None" }
};
ViewBag.dropdata = dropData;
return View();
}
AutoFill
AutoFill Feature allows you to copy the data of selected cells and paste it to another cells by just dragging the autofill icon of the selected cells up to required cells. This feature is enabled by defining EnableAutoFill
property as true.
@(Html.EJS().TreeGrid("AutoFill")
.DataSource((IEnumerable<object>)ViewBag.dataSource)
.SelectionSettings(select =>
{
select.Mode(SelectionMode.Cell);
select.CellSelectionMode(CellSelectionMode.Box);
select.Type(SelectionType.Multiple);
})
.Toolbar(new List<string>() { "Add", "Update", "Cancel" })
.EditSettings(edit =>
{
edit.AllowAdding(true);
edit.AllowEditing(true);
edit.AllowDeleting(true);
edit.Mode(Syncfusion.EJ2.TreeGrid.EditMode.Batch);
})
.Columns(col =>
{
col.Field("TaskId").HeaderText("Task ID").IsPrimaryKey(true).Width(110).TextAlign(TextAlign.Right).Add();
col.Field("TaskName").HeaderText("Task Name").Width(210).Add();
col.Field("Duration").HeaderText("Duration").TextAlign(TextAlign.Right).Width(110).Add();
col.Field("Progress").HeaderText("Progress").TextAlign(TextAlign.Right).Width(90).Add();
}).ChildMapping("Children").TreeColumnIndex(1).Height(200).EnableAutoFill(true).Render())
public IActionResult Index()
{
var treeData = TreeGridItems.GetTreeData();
ViewBag.datasource = treeData;
return View();
}
NOTE
- If
EnableAutoFill
is set to true, then the autofill icon will be displayed on cell selection to copy cells.
* It requires the selectionMode
to beCell
,CellSelectionMode
to beBox
and also Batch Editing should be enabled.
Limitations of AutoFill
- Since the string values are not parsed to number and date type, so when the selected string type cells are dragged to number type cells then it will display as NaN. For date type cells, when the selected string type cells are dragged to date type cells then it will display as an empty cell.
- Linear series and the sequential data generations are not supported in this autofill feature.
Paste
You can able to copy the content of a cell or a group of cells by selecting the cells and pressing Ctrl + C shortcut key and paste it to another set of cells by selecting the cells and pressing Ctrl + V shortcut key.
@(Html.EJS().TreeGrid("Paste")
.DataSource((IEnumerable<object>)ViewBag.dataSource)
.SelectionSettings(select =>
{
select.Mode(SelectionMode.Cell);
select.CellSelectionMode(CellSelectionMode.Box);
select.Type(SelectionType.Multiple);
})
.Toolbar(new List<string>() { "Add", "Update", "Cancel" })
.EditSettings(edit =>
{
edit.AllowAdding(true);
edit.AllowEditing(true);
edit.AllowDeleting(true);
edit.Mode(Syncfusion.EJ2.TreeGrid.EditMode.Batch);
})
.Columns(col =>
{
col.Field("TaskId").HeaderText("Task ID").IsPrimaryKey(true).Width(110).TextAlign(TextAlign.Right).Add();
col.Field("TaskName").HeaderText("Task Name").Width(210).Add();
col.Field("Duration").HeaderText("Duration").TextAlign(TextAlign.Right).Width(110).Add();
col.Field("Progress").HeaderText("Progress").TextAlign(TextAlign.Right).Width(90).Add();
}).ChildMapping("Children").TreeColumnIndex(1).Height(200).Render())
public IActionResult Index()
{
var treeData = TreeGridItems.GetTreeData();
ViewBag.datasource = treeData;
return View();
}
NOTE
To perform paste functionality, it requires the selection
Mode
to beCell
,CellSelectionMode
to beBox
and also Batch Editing should be enabled.
Limitations of Paste Functionality
- Since the string values are not parsed to number and date type, so when the copied string type cells are pasted to number type cells then it will display as NaN. For date type cells, when the copied string format cells are pasted to date type cells then it will display as an empty cell.
NOTE
You can refer to our
ASP.NET MVC Tree Grid
feature tour page for its groundbreaking feature representations. You can also explore ourASP.NET MVC Tree Grid example
to knows how to present and manipulate data.