DHTMLX Docs & Samples Explorer

Operations with clipboard

Use as delimiter:

Copy

Paste CSV content to Grid

Note: FireFox doesn't allow clipboard activity by default

Source
<link rel="STYLESHEET" type="text/css" href="../../codebase/dhtmlxgrid.css">
<link rel="stylesheet" type="text/css" href="../../codebase/skins/dhtmlxgrid_dhx_skyblue.css">
<script  src="../../codebase/dhtmlxcommon.js"></script>
<script  src="../../codebase/dhtmlxgrid.js"></script>
<script  src="../../codebase/ext/dhtmlxgrid_splt.js"></script>
<script  src="../../codebase/ext/dhtmlxgrid_nxml.js"></script>
<script  src="../../codebase/dhtmlxgridcell.js"></script>
<script>
function copyData(type, delim) {
    mygrid.setCSVDelimiter(delim);
    if (type == "all") {
        //copy entire grid;
        mygrid.gridToClipboard();
    } else if (type == "srows") {
        //selected row;
        mygrid.rowToClipboard();
    } else if (type == "cell") {
        //single cell;
        mygrid.cellToClipboard();
    }
}
function serilaizeToCSVWithDelim(delim) {
    mygrid.setCSVDelimiter(delim);
    document.getElementById('ser_1').value = mygrid.serializeToCSV();
}
</script> <div id="gridbox" style="width:600px;height:200px;background-color:white;overflow:hidden"></div> <div> <h4>Use as delimiter:</h4> <ul> <li hrei><a href="javascript:void(0)" onclick="serilaizeToCSVWithDelim('\t')">Tab</a> - \t</li> <li><a href="javascript:void(0)" onclick="serilaizeToCSVWithDelim(',')">Comma</a> - ,</li> <li><a href="javascript:void(0)" onclick="serilaizeToCSVWithDelim(document.getElementById('serdelim').value)">Other</a> <input id="serdelim" size="1" maxlength="1"></li> </ul> </div> <div> <h4>Copy</h4> <ul> <li><a href="javascript:void(0)" onclick="copyData('all','\t')">Copy entire grid (with tab as delimiter) to clipboard</a></li> <li><a href="javascript:void(0)" onclick="copyData('srows','\t')">Copy selected row(s) to clipboard</a></li> <li><a href="javascript:void(0)" onclick="copyData('cell','\t')">Copy selected cell to clipboard</a></li> </ul> </div> <div> <h4>Paste CSV content to Grid</h4> <ul> <li><a href="javascript:void(0)" onclick="mygrid.clearAll(); mygrid.gridFromClipboard();">Load grid from clipboard</a></li> <li><a href="javascript:void(0)" onclick="mygrid.updateRowFromClipboard();">Update selected row from clipboard</a></li> <li><a href="javascript:void(0)" onclick="mygrid.addRowFromClipboard();">Add row(s) from clipboard</li> <li><a href="#" onclick="mygrid.updateCellFromClipboard();">Update selected cell from clipboard</a></li> </ul> </div> <textarea style="font-size:8pt; font-family:Arial; width:800px; height:150px;" id="ser_1"></textarea> <script>
mygrid = new dhtmlXGridObject('gridbox');
mygrid.setImagePath("../../codebase/imgs/");
mygrid.setHeader("Sales,Book Title,Author,Price,In Store,Shipping,Bestseller,Date of Publication");
mygrid.setInitWidths("50,150,100,80,80,80,80,200");
mygrid.setColAlign("right,left,left,right,center,left,center,center");
mygrid.setColTypes("dyn,ed,ed,price,ch,co,ra,ro");
mygrid.getCombo(5).put(2, 2);
mygrid.enableMultiselect(true);
mygrid.setSkin("dhx_skyblue");
mygrid.init();
mygrid.splitAt(1);
mygrid.loadXML("../common/grid.xml");
window.onerror = function() {
    alert("Clipboard operations not enabled in your browser.");
    window.open("http://www.febooti.com/support/website-help/website-javascript-copy-clipboard.html", "_blank");
}
</script>