Skip to content

Commit b2d215f

Browse files
Merge pull request #121 from SylvainCorlay/scrolling-resizing
Allow for handsontable resizing
2 parents 788da4c + 1cf3d86 commit b2d215f

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

ipysheet/sheet.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import ipywidgets as widgets
2+
from ipywidgets.widgets.widget_layout import LayoutTraitType
3+
24
import traitlets
35
from traitlets import Unicode, CInt, List, Tuple, Instance, Union, Dict, Bool, Any
46

@@ -100,6 +102,8 @@ class Sheet(widgets.DOMWidget):
100102
row_resizing = Bool(True).tag(sync=True)
101103
search_token = Unicode('').tag(sync=True)
102104

105+
layout = LayoutTraitType(kw=dict(height='auto', width='auto')).tag(sync=True, **widgets.widget_serialization)
106+
103107
def __getitem__(self, item):
104108
'''Gets a previously created cell at row and column
105109

js/css/custom.css

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
.wtHolder {
2-
width: auto !important;
3-
height: auto !important;
4-
}
5-
6-
.handsontable .jupyter-widgets {
7-
width: 100%;
8-
height: 100%;
9-
}
10-
1+
/* handsontable layout*/
2+
3+
/* These properties can be overridden with the Layout widget.
4+
*
5+
* - overflow: hidden;
6+
* the first parent element with defined dimension and overflow: hidden is considered as the container for the spreadsheet
7+
*
8+
* - height: 250px;
9+
* we used a fixed value in pixels for the the natural height because `auto` yields a zero-height table in the Jupyter notebook.
10+
*
11+
*/
12+
.handsontable.jupyter-widgets {
13+
overflow: hidden;
14+
height: 250px;
15+
}
16+
17+
/* handsontable theme */
1118
.p-Widget .handsontable .table caption + thead tr:first-child th,
1219
.p-Widget .handsontable .table caption + thead tr:first-child td,
1320
.p-Widget .handsontable .table colgroup + thead tr:first-child th,

js/src/sheet.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ let SheetView = widgets.DOMWidgetView.extend({
276276
render: function() {
277277
// this.widget_view_promises = {}
278278
this.widget_views = {}
279+
this.el.classList.add("handsontable");
280+
this.el.classList.add("jupyter-widgets");
279281
this.table_container = document.createElement('div');
280282
this.el.appendChild(this.table_container);
281283
// promise used for unittesting
@@ -334,7 +336,7 @@ let SheetView = widgets.DOMWidgetView.extend({
334336
// good, the previous widget_view should be reused
335337
} else {
336338
// we have a leftover view from the previous run
337-
widget_view.remove()
339+
widget_view.remove();
338340
}
339341
}
340342
}

0 commit comments

Comments
 (0)