SMART datagrid v.1 > Examples

Back  Forward

Clipboard Paste  Example

When the user pressed ctrl+v keys, in order to paste the values of the clipboard to the selected area of the grid, pasteEnabled property of grid editOptions should be set as true first. At this point, if singlePaste is true, it will only paste in Focused Cell rather than all values. 

The default value is true.  The default value is false. 

Grid - 1
rows

In order to save the clipboard text as the data cell values rather than TEXT field, you may need to convert the format, and it can be resolved in various ways. First, you can specify the callback function in pasteCallback property of the column. It has been set in "Interest Rate" column as below. 

Code -1
    col.setPasteCallback(function (row, field, text) {
        var v = parseFloat(text);
        return isNaN(v) ? 1.0 : v;
    });

And, you can also specify editOptions.pasteCallback in the grid level. It will be ignored if column pasteCallback is specified. 

Code -2
    grid.setEditOptions({
        pasteCallback: function (row, column, field, text) {
            var v;
            switch (field.fieldName()) {
                case 'country':
                    v = text && text.indexOf('X_') != 0 ? 'X_' + text : text;
                    break;
                default:
                    v = field.readValue(text);
                    break;
            }
            return v;
        }
    });

If the callback functions are not specified, you can specify the conversion format in editOptions according to the dataType of the field. In the grid below, EditOptions.pasteDatetimeFormats, pasteBooleanFormat, pasteNumberChars have been specified as in the code below. 

Code -3
    grid.setEditOptions({
        pasteDatetimeFormats: ['yyyy-MM-dd', 'yyyyMMdd'],
        pasteBooleanFormat: "false,f:true,t:",
        pasteNumberChars: "$w,abcd"
    });

One or more date conversion formats can be specified, and pasteNumberChars specify the characters which will be excluded from the original text, so that the string can be changed to number in NUMBER

Grid - 2
rows

View Source JSP 

See Also
GridBase.editOptions
GridStyles.datetimeFormat
GridStyles.numberFormat
GridStyles.booleanFormat
GridColumn.styles
ValueColumn.copyCallback
EditOptions.copyCallback
EditOptions.copyDatetimeFormat
EditOptions.copyNumberFormat
EditOptions.copyBooleanFormat
Examples
Clipboard Copy
Cell Editing