@@ -14,7 +14,7 @@ First you need to import `StackedPanel`, `DataGrid`
14
14
and ` DataModel ` classes from lumino:
15
15
16
16
``` ts
17
- // src/index.ts#L10-L12
17
+ // src/index.ts#L16-L18
18
18
19
19
import { DataGrid , DataModel } from ' @lumino/datagrid' ;
20
20
@@ -35,14 +35,17 @@ the main area of JupyterLab as seen in the above screenshot.
35
35
With these three classes, you can create your own widget, called ` DataGridPanel ` :
36
36
37
37
``` ts
38
- // src/index.ts#L49-L63
38
+ // src/index.ts#L57-L77
39
39
40
40
class DataGridPanel extends StackedPanel {
41
- constructor () {
41
+ constructor (translator ? : ITranslator ) {
42
42
super ();
43
+ this ._translator = translator || nullTranslator ;
44
+ this ._trans = this ._translator .load (' jupyterlab' );
45
+
43
46
this .addClass (' jp-example-view' );
44
47
this .id = ' datagrid-example' ;
45
- this .title .label = ' Datagrid Example View' ;
48
+ this .title .label = this . _trans . __ ( ' Datagrid Example View' ) ;
46
49
this .title .closable = true ;
47
50
48
51
const model = new LargeDataModel ();
@@ -51,19 +54,24 @@ class DataGridPanel extends StackedPanel {
51
54
52
55
this .addWidget (grid );
53
56
}
57
+
58
+ private _translator: ITranslator ;
59
+ private _trans: TranslationBundle ;
54
60
}
55
61
```
56
62
57
63
Your widget is derived from ` StackedPanel ` to inherit its behavior. Then
58
64
some properties for the panel. Then the ` DataGrid ` widget and its associated model are created.
59
65
Finally the grid is inserted inside the panel.
60
66
67
+ Note that the private variables ` _translator ` and ` _trans ` are used for translating labels and other pieces of text that are displayed to the user.
68
+
61
69
The ` DataModel ` class is not used directly as it is an abstract class.
62
70
Therefore in this example a class ` LargeDataModel ` is derived from it
63
71
to implement its abstract methods:
64
72
65
73
``` ts
66
- // src/index.ts#L65-L74
74
+ // src/index.ts#L79-L88
67
75
68
76
class LargeDataModel extends DataModel {
69
77
rowCount(region : DataModel .RowRegion ): number {
@@ -108,7 +116,7 @@ values of the datagrid. In this case it simply displays the row and
108
116
column index in each cell, and adds a letter prefix in the header regions:
109
117
110
118
` ` ` ts
111
- // src/index.ts#L74-L85
119
+ // src/index.ts#L88-L99
112
120
113
121
data (region : DataModel .CellRegion , row : number , column : number ): any {
114
122
if (region === ' row-header' ) {
0 commit comments