Clipboard
The Clipboard class allows you to customize the behavior of the clipboard by modifying its contents using the static methods copy and paste.
Note that the Clipboard class cannot initiate clipboard operations; it can only modify the contents of the clipboard after an operation has been initiated by a user.
This example customizes copy operations from a FlexGrid by adding column headers to the clipboard content. To see how it works, copy a range from the FlexGrid and paste into an Excel sheet.
Id
Country
Product
Active
Downloads
Sales
Expenses
Overdue
0
US
Phones
145,248
81,732.54
38,401.13
1
Germany
Computers
111,632
20,603.32
27,944.24
2
UK
Cameras
181,205
44,217.79
48,877.49
3
Japan
Stereos
54,740
29,190.63
23,365.74
4
Italy
Phones
126,531
46,951.19
49,107.56
5
Greece
Computers
6,073
86,237.02
49,767.35
Id
Country
Product
Active
Downloads
Sales
Expenses
Overdue
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | // This file locates: "Scripts/Lesson/C1Mvc/Clipboard.js". c1.documentReady(function () { var hasHeaders = false ; var theGrid = wijmo.Control.getControl( '#theGrid' ); theGrid.copying.addHandler(function (s, e) { // // add headers to clip string hasHeaders = false ; var includeHeaders = document.getElementById( 'includeHeaders' ). checked ; if (includeHeaders) { var text = s.getClipString(), sel = s.selection, hdr = '' ; for (var c = sel.leftCol; c <= sel.rightCol; c++) { if (hdr) hdr += '\t' ; hdr += s.columns[c].header; } text = hdr + '\r\n' + text; // put text with headers on the clipboard wijmo.Clipboard.copy(text); hasHeaders = true ; // prevent the grid from overwriting our clipboard content e.cancel = true ; } }); theGrid.pasting.addHandler(function (s, e) { // prevent pasting content with headers... if (hasHeaders) { e.cancel = true ; } }); }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 | using System.Web.Mvc; namespace LearnMvcClient.Controllers { public partial class C1MvcController : Controller { // GET: Clipboard public ActionResult Clipboard() { return View(Models.FlexGridData.GetSales()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | @model IEnumerable< FlexGridData.Sale > < h1 > @Html .Raw(Resources.C1Mvc.Clipboard_Title) </ h1 > < p > @Html .Raw(Resources.C1Mvc.Clipboard_Text1) </ p > < p > @Html .Raw(Resources.C1Mvc.Clipboard_Text2) </ p > < p > @Html .Raw(Resources.C1Mvc.Clipboard_Text3) </ p > < label > @Html .Raw(Resources.C1Mvc.Clipboard_Text4) < input id = "includeHeaders" type = "checkbox" checked = "true" > </ label > @ (Html.C1().FlexGrid< FlexGridData.Sale >().Id( "theGrid" ).Bind(Model)) |