Skip to content

Commit ca282f2

Browse files
committed
Updated embedded code snippets in readme
1 parent 6182b0b commit ca282f2

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

basics/datagrid/README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ First you need to import `StackedPanel`, `DataGrid`
1414
and `DataModel` classes from lumino:
1515

1616
```ts
17-
// src/index.ts#L10-L12
17+
// src/index.ts#L16-L18
1818

1919
import { DataGrid, DataModel } from '@lumino/datagrid';
2020

@@ -35,14 +35,17 @@ the main area of JupyterLab as seen in the above screenshot.
3535
With these three classes, you can create your own widget, called `DataGridPanel` :
3636

3737
```ts
38-
// src/index.ts#L49-L63
38+
// src/index.ts#L57-L77
3939

4040
class DataGridPanel extends StackedPanel {
41-
constructor() {
41+
constructor(translator?: ITranslator) {
4242
super();
43+
this._translator = translator || nullTranslator;
44+
this._trans = this._translator.load('jupyterlab');
45+
4346
this.addClass('jp-example-view');
4447
this.id = 'datagrid-example';
45-
this.title.label = 'Datagrid Example View';
48+
this.title.label = this._trans.__('Datagrid Example View');
4649
this.title.closable = true;
4750

4851
const model = new LargeDataModel();
@@ -51,19 +54,24 @@ class DataGridPanel extends StackedPanel {
5154

5255
this.addWidget(grid);
5356
}
57+
58+
private _translator: ITranslator;
59+
private _trans: TranslationBundle;
5460
}
5561
```
5662

5763
Your widget is derived from `StackedPanel` to inherit its behavior. Then
5864
some properties for the panel. Then the `DataGrid` widget and its associated model are created.
5965
Finally the grid is inserted inside the panel.
6066

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+
6169
The `DataModel` class is not used directly as it is an abstract class.
6270
Therefore in this example a class `LargeDataModel` is derived from it
6371
to implement its abstract methods:
6472

6573
```ts
66-
// src/index.ts#L65-L74
74+
// src/index.ts#L79-L88
6775

6876
class LargeDataModel extends DataModel {
6977
rowCount(region: DataModel.RowRegion): number {
@@ -108,7 +116,7 @@ values of the datagrid. In this case it simply displays the row and
108116
column index in each cell, and adds a letter prefix in the header regions:
109117
110118
```ts
111-
// src/index.ts#L74-L85
119+
// src/index.ts#L88-L99
112120

113121
data(region: DataModel.CellRegion, row: number, column: number): any {
114122
if (region === 'row-header') {

0 commit comments

Comments
 (0)