:: Forum >>

Better way of doing copy & paste?

Here's the code i came up with to copy all the values and paste all the values into my grid. It seems to work fine but i have a few problems.

1. Is there a more efficient way of copying all the values (tab delimited) so i can paste it into excel.

2. Is there a more efficient way to paste?

3. I added a keyboard handler to handle copy & paste, but if i replace the keydown event with my handler, the navigation keys don't work any more. How can i restore it?

4. I'm using an array to populate the grid, but after i make the addRow call even though i can see the new row added, when i do a copy_all i don't see any data in the newly added rows (just carriage returns).... looks like calling addRow is not sufficient.

====================================

// the clipboard feature as far as i know only work in IE.

function copy_all(grid)
{
var columns = grid.getColumnCount();
var rows = grid.getRowCount();
var text = '';
for(var r=0; r < rows; r++)
{
for(var c=0; c < columns; c++)
{
text += grid.getCellText(c, r) + '\t';
}
text += '\r\n';
}
clipboardData.setData("Text", text);
}

function paste_all(grid)
{
try
{
var text = clipboardData.getData("Text");
var copiedRows = text.split('\r\n');
for(var r=0; r < copiedRows[0].length; r++)
{
if ( copiedRows[r] != null )
{
var items = copiedRows[r].split('\t');
for(c=0; c < items.length; c++)
{
grid.setCellText(items[c], c, r);
}
}
}
} catch(e) {alert(e);}
}


var keydown_handler = function (event)
{
try
{
if(event.ctrlKey)
{
var key=event.keyCode;
if (key==67) // Ctrl-c copies all visible cells into the clipboard
{
copy_all(this);
}
if (key==86) // Ctrl-v
{
paste_all(this);
}
}
alert(default_keydown_handler);
} catch (e) {
alert('here---------->' + e);
}
};
Sunday, February 12, 2006
Forgot to say who I am...
Michael L (CA)
Sunday, February 12, 2006

This topic is archived.


Back to support forum

Forum search