Skip to content

Commit

Permalink
bugfix: use default cell editor for a cell that has declared only cel…
Browse files Browse the repository at this point in the history
…l renderer (#453)
  • Loading branch information
warpech committed Feb 28, 2013
1 parent b09f6d3 commit a5c61a2
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## HEAD

Bugfixes:
- use default cell editor for a cell that has declared only cell renderer ([#453](https://github.com/warpech/jquery-handsontable/issues/453)
- copy/paste did not work on Mac since 0.8.6 ([#348](https://github.com/warpech/jquery-handsontable/issues/348)
- global shortcuts (like CTRL+A) should be blocked when cell is being edited
- numeric cell editor did not convert cell data to number type when data source was an object
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.handsontable.full.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Thu Feb 28 2013 14:30:22 GMT+0100 (Central European Standard Time)
* Date: Thu Feb 28 2013 14:47:58 GMT+0100 (Central European Standard Time)
*/

.handsontable {
Expand Down
24 changes: 14 additions & 10 deletions dist/jquery.handsontable.full.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Thu Feb 28 2013 14:30:22 GMT+0100 (Central European Standard Time)
* Date: Thu Feb 28 2013 14:47:58 GMT+0100 (Central European Standard Time)
*/
/*jslint white: true, browser: true, plusplus: true, indent: 4, maxerr: 50 */

Expand Down Expand Up @@ -1727,8 +1727,11 @@ Handsontable.Core = function (rootElement, settings) {
* @return {Object}
*/
this.getCellMeta = function (row, col) {
var cellProperties = {}
, prop = datamap.colToProp(col);
var cellProperties = $.extend(true, cellProperties, Handsontable.TextCell)
, prop = datamap.colToProp(col)
, i
, type;

if (priv.settings.columns) {
cellProperties = $.extend(true, cellProperties, priv.settings.columns[col] || {});
}
Expand All @@ -1738,18 +1741,19 @@ Handsontable.Core = function (rootElement, settings) {
Handsontable.PluginHooks.run(self, 'beforeGetCellMeta', row, col, cellProperties);

if (typeof cellProperties.type === 'string' && Handsontable.cellTypes[cellProperties.type]) {
cellProperties = $.extend(true, cellProperties, Handsontable.cellTypes[cellProperties.type]);
type = Handsontable.cellTypes[cellProperties.type];
}
else if (typeof cellProperties.type === 'object') {
for (var i in cellProperties.type) {
if (cellProperties.type.hasOwnProperty(i)) {
cellProperties[i] = cellProperties.type[i];
type = cellProperties.type;
}

if (type) {
for (i in type) {
if (type.hasOwnProperty(i)) {
cellProperties[i] = type[i];
}
}
}
else {
cellProperties = $.extend(true, cellProperties, Handsontable.TextCell);
}

cellProperties.isWritable = !cellProperties.readOnly;
Handsontable.PluginHooks.run(self, 'afterGetCellMeta', row, col, cellProperties);
Expand Down
2 changes: 1 addition & 1 deletion jquery.handsontable.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Thu Feb 28 2013 14:30:22 GMT+0100 (Central European Standard Time)
* Date: Thu Feb 28 2013 14:47:58 GMT+0100 (Central European Standard Time)
*/

.handsontable {
Expand Down
24 changes: 14 additions & 10 deletions jquery.handsontable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Thu Feb 28 2013 14:30:22 GMT+0100 (Central European Standard Time)
* Date: Thu Feb 28 2013 14:47:58 GMT+0100 (Central European Standard Time)
*/
/*jslint white: true, browser: true, plusplus: true, indent: 4, maxerr: 50 */

Expand Down Expand Up @@ -1727,8 +1727,11 @@ Handsontable.Core = function (rootElement, settings) {
* @return {Object}
*/
this.getCellMeta = function (row, col) {
var cellProperties = {}
, prop = datamap.colToProp(col);
var cellProperties = $.extend(true, cellProperties, Handsontable.TextCell)
, prop = datamap.colToProp(col)
, i
, type;

if (priv.settings.columns) {
cellProperties = $.extend(true, cellProperties, priv.settings.columns[col] || {});
}
Expand All @@ -1738,18 +1741,19 @@ Handsontable.Core = function (rootElement, settings) {
Handsontable.PluginHooks.run(self, 'beforeGetCellMeta', row, col, cellProperties);

if (typeof cellProperties.type === 'string' && Handsontable.cellTypes[cellProperties.type]) {
cellProperties = $.extend(true, cellProperties, Handsontable.cellTypes[cellProperties.type]);
type = Handsontable.cellTypes[cellProperties.type];
}
else if (typeof cellProperties.type === 'object') {
for (var i in cellProperties.type) {
if (cellProperties.type.hasOwnProperty(i)) {
cellProperties[i] = cellProperties.type[i];
type = cellProperties.type;
}

if (type) {
for (i in type) {
if (type.hasOwnProperty(i)) {
cellProperties[i] = type[i];
}
}
}
else {
cellProperties = $.extend(true, cellProperties, Handsontable.TextCell);
}

cellProperties.isWritable = !cellProperties.readOnly;
Handsontable.PluginHooks.run(self, 'afterGetCellMeta', row, col, cellProperties);
Expand Down
22 changes: 13 additions & 9 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1708,8 +1708,11 @@ Handsontable.Core = function (rootElement, settings) {
* @return {Object}
*/
this.getCellMeta = function (row, col) {
var cellProperties = {}
, prop = datamap.colToProp(col);
var cellProperties = $.extend(true, cellProperties, Handsontable.TextCell)
, prop = datamap.colToProp(col)
, i
, type;

if (priv.settings.columns) {
cellProperties = $.extend(true, cellProperties, priv.settings.columns[col] || {});
}
Expand All @@ -1719,18 +1722,19 @@ Handsontable.Core = function (rootElement, settings) {
Handsontable.PluginHooks.run(self, 'beforeGetCellMeta', row, col, cellProperties);

if (typeof cellProperties.type === 'string' && Handsontable.cellTypes[cellProperties.type]) {
cellProperties = $.extend(true, cellProperties, Handsontable.cellTypes[cellProperties.type]);
type = Handsontable.cellTypes[cellProperties.type];
}
else if (typeof cellProperties.type === 'object') {
for (var i in cellProperties.type) {
if (cellProperties.type.hasOwnProperty(i)) {
cellProperties[i] = cellProperties.type[i];
type = cellProperties.type;
}

if (type) {
for (i in type) {
if (type.hasOwnProperty(i)) {
cellProperties[i] = type[i];
}
}
}
else {
cellProperties = $.extend(true, cellProperties, Handsontable.TextCell);
}

cellProperties.isWritable = !cellProperties.readOnly;
Handsontable.PluginHooks.run(self, 'afterGetCellMeta', row, col, cellProperties);
Expand Down
28 changes: 28 additions & 0 deletions test/jasmine/spec/Core_getCellMetaSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,32 @@ describe('Core_getCellMeta', function () {
expect(isEditorVisible()).toEqual(true);
});
});

it('should use default cell editor for a cell that has declared only cell renderer', function () {
handsontable({
cells: function () {
return {
type: {
renderer: function (instance, td, row, col, prop, value, cellProperties) {
//taken from demo/renderers.html
Handsontable.TextCell.renderer.apply(this, arguments);
$(td).css({
background: 'yellow'
});
}
}
}
}
});
selectCell(2, 2);

waitsFor(nextFrame, 'next frame', 60);

runs(function () {
keyDown('enter');
document.activeElement.value = 'new value';
destroyEditor();
expect(getDataAtCell(2, 2)).toEqual('new value');
});
});
});

0 comments on commit a5c61a2

Please sign in to comment.