vendor/assets/javascripts/slickgrid/plugins/cellexternalcopymanager.js in slickgrid-2.3.16.1 vs vendor/assets/javascripts/slickgrid/plugins/cellexternalcopymanager.js in slickgrid-2.4.5
- old
+ new
@@ -26,10 +26,11 @@
bodyElement: option to specify a custom DOM element which to will be added the hidden textbox. It's useful if the grid is inside a modal dialog.
onCopyInit: optional handler to run when copy action initializes
onCopySuccess: optional handler to run when copy action is complete
newRowCreator: function to add rows to table if paste overflows bottom of table, if this function is not provided new rows will be ignored.
readOnlyMode: suppresses paste
+ headerColumnValueExtractor : option to specify a custom column header value extractor function
*/
var _grid;
var _self = this;
var _copiedRanges;
var _options = options || {};
@@ -65,27 +66,37 @@
function destroy() {
_grid.onKeyDown.unsubscribe(handleKeyDown);
}
- function getDataItemValueForColumn(item, columnDef) {
+ function getHeaderValueForColumn(columnDef) {
+ if (_options.headerColumnValueExtractor) {
+ var val = _options.headerColumnValueExtractor(columnDef);
+
+ if (val) { return val; }
+ }
+
+ return columnDef.name;
+ }
+
+ function getDataItemValueForColumn(item, columnDef, e) {
if (_options.dataItemColumnValueExtractor) {
- var dataItemColumnValueExtractorValue = _options.dataItemColumnValueExtractor(item, columnDef);
+ var val = _options.dataItemColumnValueExtractor(item, columnDef);
- if (dataItemColumnValueExtractorValue)
- return dataItemColumnValueExtractorValue;
+ if (val) { return val; }
}
var retVal = '';
// if a custom getter is not defined, we call serializeValue of the editor to serialize
if (columnDef.editor){
var editorArgs = {
'container':$("<p>"), // a dummy container
'column':columnDef,
'position':{'top':0, 'left':0}, // a dummy position required by some editors
- 'grid':_grid
+ 'grid':_grid,
+ 'event':e
};
var editor = new columnDef.editor(editorArgs);
editor.loadValue(item);
retVal = editor.serializeValue();
editor.destroy();
@@ -95,10 +106,12 @@
return retVal;
}
function setDataItemValueForColumn(item, columnDef, value) {
+ if (columnDef.denyPaste) { return null; }
+
if (_options.dataItemColumnValueSetter) {
return _options.dataItemColumnValueSetter(item, columnDef, value);
}
// if a custom setter is not defined, we call applyValue of the editor to unserialize
@@ -346,17 +359,17 @@
if (clipTextRows == "" && _options.includeHeaderWhenCopying) {
var clipTextHeaders = [];
for (var j = range.fromCell; j < range.toCell + 1 ; j++) {
if (columns[j].name.length > 0)
- clipTextHeaders.push(columns[j].name);
+ clipTextHeaders.push(getHeaderValueForColumn(columns[j]));
}
clipTextRows.push(clipTextHeaders.join("\t"));
}
for (var j=range.fromCell; j< range.toCell+1 ; j++){
- clipTextCells.push(getDataItemValueForColumn(dt, columns[j]));
+ clipTextCells.push(getDataItemValueForColumn(dt, columns[j], e));
}
clipTextRows.push(clipTextCells.join("\t"));
}
clipText += clipTextRows.join("\r\n") + "\r\n";
}
@@ -436,17 +449,24 @@
function clearCopySelection() {
_grid.removeCellCssStyles(_copiedCellStyleLayerKey);
}
+ function setIncludeHeaderWhenCopying(includeHeaderWhenCopying) {
+ _options.includeHeaderWhenCopying = includeHeaderWhenCopying;
+ }
+
$.extend(this, {
"init": init,
"destroy": destroy,
+ "pluginName": "CellExternalCopyManager",
+
"clearCopySelection": clearCopySelection,
"handleKeyDown":handleKeyDown,
"onCopyCells": new Slick.Event(),
"onCopyCancelled": new Slick.Event(),
- "onPasteCells": new Slick.Event()
+ "onPasteCells": new Slick.Event(),
+ "setIncludeHeaderWhenCopying" : setIncludeHeaderWhenCopying
});
}
-})(jQuery);
+})(jQuery);
\ No newline at end of file