From 457f7b9957dfb6546e66552dc187e98426073348 Mon Sep 17 00:00:00 2001 From: Ben McIntyre Date: Fri, 18 Aug 2017 23:01:13 +0930 Subject: [PATCH] fix various minor bugs including #141, #142 --- ...excel-compatible-spreadsheet-dataview.html | 231 ++++++++++++++++++ .../example-excel-compatible-spreadsheet.html | 23 +- examples/example5-collapsing.html | 2 + examples/examples.css | 2 +- plugins/slick.cellexternalcopymanager.js | 5 +- slick.grid.js | 8 +- 6 files changed, 262 insertions(+), 9 deletions(-) create mode 100644 examples/example-excel-compatible-spreadsheet-dataview.html diff --git a/examples/example-excel-compatible-spreadsheet-dataview.html b/examples/example-excel-compatible-spreadsheet-dataview.html new file mode 100644 index 000000000..b4b8c4143 --- /dev/null +++ b/examples/example-excel-compatible-spreadsheet-dataview.html @@ -0,0 +1,231 @@ + + + + + + SlickGrid example: Spreadsheet with Excel compatible cut and paste + + + + + + +
+
+
+
+
+
+
+
+ +
+

Excel compatible copy/paste manager using DataView

+
+ Thanks to Celebio! (link to site)

+ This is basically the same example than example-spreadsheet.html, + with the support of external excel-compatible software clipboard
+
+

Paste from Excel-compatible:

+
    +
  • Copy a range of cells to clipboard in Excel
  • +
  • Select a cell on slickgrid
  • +
  • Use Ctrl-V keyboard shortcut to paste from the clipboard
  • +
  • Adds rows to bottom of grid if paste overflows
  • +
+

Copy for Excel-compatible:

+
    +
  • Select a range of cells with a mouse
  • +
  • Use Ctrl-C shortcut to copy cells
  • +
  • You can paste the tabular data into Excel
  • +
+ +

Undo/redo support :

+
    +
  • Use buttons to undo/redo copy/paste
  • +
+ + +

View Source:

+ +
+
+ + + + + + + + + + + + + + + + + + + + + diff --git a/examples/example-excel-compatible-spreadsheet.html b/examples/example-excel-compatible-spreadsheet.html index ddec96ae6..2d6c5acc4 100644 --- a/examples/example-excel-compatible-spreadsheet.html +++ b/examples/example-excel-compatible-spreadsheet.html @@ -3,7 +3,7 @@ - SlickGrid example 3: Editing + SlickGrid example: Spreadsheet with Excel compatible cut and paste @@ -20,8 +20,9 @@
+
-
+
@@ -80,6 +81,24 @@

View Source:

var data = []; var data2 = []; + // sample of use of optional get and set functions + // (otherwise the editor is used to serialise the data to a string, + // then as a fallback the data value is used as-is) + + // function getVal(item, columnDef) { + // return item[columnDef.field]; + // } + // + // function setVal(item, columnDef, value) { + // item[columnDef.field] = value; + // } + // + // var options = { + // ... , + // dataItemColumnValueExtractor: getVal, + // dataItemColumnValueSetter: setVal + // }; + var options = { editable: true, enableAddRow: true, diff --git a/examples/example5-collapsing.html b/examples/example5-collapsing.html index 5bf11a088..a118cf293 100644 --- a/examples/example5-collapsing.html +++ b/examples/example5-collapsing.html @@ -87,6 +87,8 @@

View Source:

var TaskNameFormatter = function (row, cell, value, columnDef, dataContext) { + if (value == null || value == undefined || dataContext === undefined) { return ""; } + value = value.replace(/&/g,"&").replace(//g,">"); var spacer = ""; var idx = dataView.getIdxById(dataContext.id); diff --git a/examples/examples.css b/examples/examples.css index 9bd4839ea..f932fa74c 100644 --- a/examples/examples.css +++ b/examples/examples.css @@ -30,7 +30,7 @@ ul { margin: 0; } -#myGrid { +#myGrid, .example-grid { background: white; outline: 0; border: 1px solid gray; diff --git a/plugins/slick.cellexternalcopymanager.js b/plugins/slick.cellexternalcopymanager.js index fec7cb2a4..ce64ebe4d 100644 --- a/plugins/slick.cellexternalcopymanager.js +++ b/plugins/slick.cellexternalcopymanager.js @@ -89,8 +89,7 @@ editor.loadValue(item); retVal = editor.serializeValue(); editor.destroy(); - } - else { + } else { retVal = item[columnDef.field]; } @@ -114,6 +113,8 @@ editor.loadValue(item); editor.applyValue(item, value); editor.destroy(); + } else { + item[columnDef.field] = value; } } diff --git a/slick.grid.js b/slick.grid.js index f816fa78c..7f2cbd431 100644 --- a/slick.grid.js +++ b/slick.grid.js @@ -3607,8 +3607,8 @@ if (typeof Slick === "undefined") { this.editor.applyValue(item, this.serializedValue); updateRow(this.row); trigger(self.onCellChange, { - row: activeRow, - cell: activeCell, + row: this.row, + cell: this.cell, item: item, grid: self }); @@ -3617,8 +3617,8 @@ if (typeof Slick === "undefined") { this.editor.applyValue(item, this.prevSerializedValue); updateRow(this.row); trigger(self.onCellChange, { - row: activeRow, - cell: activeCell, + row: this.row, + cell: this.cell, item: item, grid: self });