Skip to content

Commit

Permalink
Merge pull request #32 from martinRenou/update_handsontable_version
Browse files Browse the repository at this point in the history
Update handsontable
  • Loading branch information
SylvainCorlay committed Feb 19, 2019
2 parents 64e28e9 + 79ab04c commit 1a0321f
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 19 deletions.
50 changes: 50 additions & 0 deletions examples/format.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ipysheet"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sheet = ipysheet.sheet()\n",
"cell0 = ipysheet.cell(0, 0, 0, numeric_format='0.0', type='numeric')\n",
"cell1 = ipysheet.cell(1, 0, \"Hello\", type='text')\n",
"cell2 = ipysheet.cell(0, 1, 0.1, numeric_format='0.000', type='numeric')\n",
"cell3 = ipysheet.cell(1, 1, 15.9, numeric_format='0.00', type='numeric')\n",
"cell4 = ipysheet.cell(2, 2, \"02/14/2019\", date_format='MM/DD/YYYY', type='date')\n",
"\n",
"sheet"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
7 changes: 4 additions & 3 deletions ipysheet/easy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def current():

def cell(row, column, value=0., type=None, color=None, background_color=None,
font_style=None, font_weight=None, style=None, label_left=None, choice=None,
read_only=False, format='0.[000]', renderer=None):
read_only=False, numeric_format='0.[000]', date_format='YYYY/MM/DD', renderer=None, **kwargs):
"""Adds a new `Cell` widget to the current sheet
Parameters
Expand Down Expand Up @@ -106,8 +106,9 @@ def cell(row, column, value=0., type=None, color=None, background_color=None,
if font_weight is not None:
style['fontWeight'] = font_weight
c = Cell(value=value, row_start=row, column_start=column, row_end=row, column_end=column,
squeeze_row=True, squeeze_column=True, type=type, style=style,
read_only=read_only, choice=choice, renderer=renderer, format=format)
squeeze_row=True, squeeze_column=True, type=type, style=style, choice=choice,
read_only=False, numeric_format=numeric_format, date_format=date_format,
renderer=renderer, **kwargs)
if _hold_cells:
_cells += (c,)
else:
Expand Down
3 changes: 2 additions & 1 deletion ipysheet/sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class Cell(widgets.Widget):
squeeze_column = Bool(True).tag(sync=True)
transpose = Bool(False).tag(sync=True)
choice = List(Unicode(), allow_none=True, default_value=None).tag(sync=True)
format = Unicode('0.[000]', allow_none=True).tag(sync=True)
numeric_format = Unicode('0.[000]', allow_none=True).tag(sync=True)
date_format = Unicode('YYYY/MM/DD', allow_none=True).tag(sync=True)

@traitlets.validate('value')
def _validate_value(self, proposal):
Expand Down
30 changes: 19 additions & 11 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"dependencies": {
"@jupyter-widgets/base": "^1.0.1",
"@jupyter-widgets/jupyterlab-manager": "^0.28.0",
"handsontable": "^0.34.1",
"handsontable": "^6.2.2",
"lodash": "^4.17.4",
"underscore": "^1.8.3"
}
Expand Down
1 change: 1 addition & 0 deletions js/src/handsontable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Handsontable from 'handsontable/dist/handsontable.full.js';

import 'pikaday/css/pikaday.css';
import 'handsontable/dist/handsontable.min.css';
import '../../src/custom.css';

Expand Down
13 changes: 10 additions & 3 deletions js/src/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ let CellRangeModel = widgets.WidgetModel.extend({
squeeze_row: true,
squeeze_column: true,
transpose: false,
format: '0.[000]'
numeric_format: '0.[000]',
date_format: 'YYYY/MM/DD'
});
},
});
Expand Down Expand Up @@ -82,7 +83,7 @@ let SheetModel = widgets.DOMWidgetModel.extend({
this.grid_to_cell()
},
cell_bind: function(cell) {
cell.on('change:value change:style change:type change:renderer change:read_only change:choice change:format', function() {
cell.on('change:value change:style change:type change:renderer change:read_only change:choice change:numeric_format change:date_format', function() {
this.cells_to_grid()
}, this);
},
Expand Down Expand Up @@ -125,7 +126,13 @@ let SheetModel = widgets.DOMWidgetModel.extend({
cell_data.options['renderer'] = cell.get('renderer') || cell_data.options['renderer'];
cell_data.options['readOnly'] = cell.get('read_only') || cell_data.options['readOnly'];
cell_data.options['source'] = cell.get('choice') || cell_data.options['source'];
cell_data.options['format'] = cell.get('format') || cell_data.options['format'];
if (cell.get('numeric_format') && cell.get('type') == 'numeric') {
cell_data.options['numericFormat'] = {'pattern': cell.get('numeric_format')};
}
if (cell.get('date_format') && cell.get('type') == 'date') {
cell_data.options['correctFormat'] = true;
cell_data.options['dateFormat'] = cell.get('date_format') || cell_data.options['dateFormat'];
}
}
}
},
Expand Down

0 comments on commit 1a0321f

Please sign in to comment.