Skip to content

Commit

Permalink
Merge pull request #117 from martinRenou/add_time_celltype
Browse files Browse the repository at this point in the history
Add time cell type
  • Loading branch information
martinRenou committed May 2, 2019
2 parents e7aec62 + adc1f88 commit ddbe74b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions ipysheet/easy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
read_only (bool): Whether the cell is editable or not
numeric_format (string): Numbers format
date_format (string): Dates format
time_format (string): Time format
renderer (string): Renderer name to use for the cell
"""
}
Expand Down
1 change: 1 addition & 0 deletions ipysheet/sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Cell(widgets.Widget):
choice = List(Unicode(), allow_none=True, default_value=None).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)
time_format = Unicode('h:mm:ss a', allow_none=True).tag(sync=True)

@traitlets.validate('value')
def _validate_value(self, proposal):
Expand Down
9 changes: 7 additions & 2 deletions js/src/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ let CellRangeModel = widgets.WidgetModel.extend({
squeeze_column: true,
transpose: false,
numeric_format: '0.000',
date_format: 'YYYY/MM/DD'
date_format: 'YYYY/MM/DD',
time_format: 'h:mm:ss a'
});
},
}, {
Expand Down Expand Up @@ -95,7 +96,7 @@ let SheetModel = widgets.DOMWidgetModel.extend({
this.grid_to_cell()
},
cell_bind: function(cell) {
cell.on_some_change(['value', 'style', 'type', 'renderer', 'read_only', 'choice', 'numeric_format', 'date_format'], () => {
cell.on_some_change(['value', 'style', 'type', 'renderer', 'read_only', 'choice', 'numeric_format', 'date_format', 'time_format'], () => {
this.cells_to_grid();
});
},
Expand Down Expand Up @@ -145,6 +146,10 @@ let SheetModel = widgets.DOMWidgetModel.extend({
cell_data.options['correctFormat'] = true;
cell_data.options['dateFormat'] = cell.get('date_format') || cell_data.options['dateFormat'];
}
if (cell.get('time_format') && cell.get('type') == 'time') {
cell_data.options['correctFormat'] = true;
cell_data.options['timeFormat'] = cell.get('time_format') || cell_data.options['timeFormat'];
}

cell_data.options['style'] = extend({}, cell_data.options['style'], cell.get('style'));
}
Expand Down

0 comments on commit ddbe74b

Please sign in to comment.