How to copy and paste in javascript grid

Compatibility with any spreadsheet

Copy paste functionality of ParamQuery grid is compatible with any spreadsheet application like MS Excel i.e., data can be copied from ParamQuery Grid and pasted to other spreadsheets and vice versa.

Keyboard operations:

Ctrl A: Select All cells.
Ctrl C: Copy selection which is available for paste.
Ctrl X: Cut selection which is available for paste.
Delete: Delete selection.
Ctrl V: Paste data.
Ctrl Z: Undo
Ctrl Y: Redo

Please note:

Skip rows / columns from copied data during initialization

By default all the rows and columns in a Range or Selection of cells are copied. Columns can be skipped from copied data by setting column.copy to false. Similarly rows can be skipped from copied data by setting pq_copy property to false.

Skip rows / columns from copied data during run time

Sometimes it's required to skip rows and columns conditionally in run time e.g. skip hidden rows and columns while copying. To ahieve that, we convert column.copy property to javascript getter, which can be defined in the grid initialization object. Furthermore columnTemplate can be used to propagate getter copy property to all columns.

columnTemplate: {
    get copy(){           
        return !this.hidden;
    }
}

or by updating existing grid initialization object (before initialization of grid)

Object.defineProperty(obj.columnTemplate, 'copy', {
    enumerable: true,
    get (){           
        return !this.hidden;
    }
})

Similarly it can be set up for rows by using their counterpart properties, rowTemplate, rowData.pq_hidden, rowData.pq_copy.

Skip target rows / columns when pasting data during initialization

By default all the target rows and columns are pasted over by copied data. Target columns can be skipped by setting column.paste to false. Similarly target rows can be skipped by setting pq_paste property to false.

Skip target rows / columns when pasting data during run time

Sometimes it's required to skip rows and columns in target grid conditionally in run time e.g., to skip hidden rows and columns in the target Range/Selection while pasting. To ahieve that, column.paste can be linked to column.hidden property by using javascript getters which can be defined in the grid initialization object. We use columnTemplate to propagate paste property to all columns.

columnTemplate: {
    get paste(){           
        return !this.hidden;
    }
}

or by updating existing grid initialization object (before initialization of grid)

Object.defineProperty(obj.columnTemplate, 'paste', {
    enumerable: true,
    get (){           
        return !this.hidden;
    }
})

Similarly it can be set up for rows by using their counterpart properties, rowTemplate, rowData.pq_hidden, rowData.pq_paste.