Skip to content

Commit ed811fe

Browse files
committed
Separate function to apply styling
Signed-off-by: Itay Dafna <[email protected]>
1 parent 066c518 commit ed811fe

File tree

3 files changed

+48
-33
lines changed

3 files changed

+48
-33
lines changed

js/cellrenderer.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ export class TextRendererModel extends CellRendererModel {
245245
}
246246

247247
get_attrs(): ICellRendererAttribute[] {
248-
const gridStyle = this.get('grid_style');
249-
console.log(gridStyle);
250248
return [
251249
{ name: 'font', phosphorName: 'font', defaultValue: '12px sans-serif' },
252250
{ name: 'text_wrap', phosphorName: 'wrapText', defaultValue: false },
@@ -264,7 +262,7 @@ export class TextRendererModel extends CellRendererModel {
264262
{
265263
name: 'background_color',
266264
phosphorName: 'backgroundColor',
267-
defaultValue: undefined,
265+
defaultValue: Theme.getBackgroundColor(),
268266
},
269267
{
270268
name: 'vertical_alignment',

js/datagrid.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ export class DataGridView extends DOMWidgetView {
357357
this.grid.isLightTheme = this._isLightTheme;
358358
this.grid.dataModel = this.model.data_model;
359359
this.grid.selectionModel = this.model.selectionModel;
360+
this.grid.backboneModel = this.model;
360361

361362
this.grid.cellClicked.connect(
362363
(sender: FeatherGrid, event: FeatherGrid.ICellClickedEvent) => {
@@ -438,7 +439,7 @@ export class DataGridView extends DOMWidgetView {
438439
return this.updateRenderers().then(() => {
439440
this.updateGridStyle();
440441
this.updateGridRenderers();
441-
442+
this.grid.setGridStyle();
442443
this.pWidget.addWidget(this.grid);
443444
});
444445
}
@@ -518,6 +519,7 @@ export class DataGridView extends DOMWidgetView {
518519

519520
public updateGridStyle() {
520521
this.grid.updateGridStyle();
522+
this.grid.setGridStyle();
521523
}
522524

523525
set isLightTheme(value: boolean) {
@@ -575,6 +577,7 @@ export class DataGridView extends DOMWidgetView {
575577
grid: FeatherGrid;
576578
pWidget: JupyterPhosphorPanelWidget;
577579
model: DataGridModel;
580+
backboneModel: DataGridModel;
578581

579582
// keep undefined since widget initializes before constructor
580583
private _isLightTheme: boolean;

js/feathergrid.ts

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { Transform } from './core/transform';
2020
import { Theme } from './utils';
2121
import { KeyHandler } from './keyhandler';
2222

23+
import { DataGridModel as BackBoneModel } from './datagrid';
24+
2325
import '@lumino/default-theme/style/datagrid.css';
2426
import '../style/feathergrid.css';
2527

@@ -518,39 +520,16 @@ export class FeatherGrid extends Widget {
518520
this.updateGridStyle();
519521
this._updateGridRenderers();
520522
this._updateColumnWidths();
523+
this.setGridStyle();
521524
}
522525

523-
public updateGridStyle() {
524-
this._updateHeaderRenderer();
525-
526-
if (!this._defaultRendererSet) {
527-
this._defaultRenderer = new TextRenderer({
528-
font: '12px sans-serif',
529-
textColor: Theme.getFontColor(),
530-
backgroundColor: Theme.getBackgroundColor(),
531-
horizontalAlignment: 'left',
532-
verticalAlignment: 'center',
533-
});
526+
public setGridStyle() {
527+
// Resetting grid style if theme changes.
528+
if (this.backboneModel) {
529+
this.grid.style = this.backboneModel.get('grid_style');
534530
}
535531

536-
this._rowHeaderRenderer = new TextRenderer({
537-
textColor: Theme.getFontColor(1),
538-
backgroundColor: Theme.getBackgroundColor(2),
539-
horizontalAlignment: 'center',
540-
verticalAlignment: 'center',
541-
});
542-
543-
this._columnHeaderRenderer = new HeaderRenderer({
544-
textOptions: {
545-
textColor: Theme.getFontColor(1),
546-
backgroundColor: Theme.getBackgroundColor(2),
547-
horizontalAlignment: 'left',
548-
verticalAlignment: 'center',
549-
},
550-
isLightTheme: this._isLightTheme,
551-
grid: this.grid,
552-
});
553-
532+
// Setting up theme.
554533
const scrollShadow = {
555534
size: 4,
556535
color1: Theme.getBorderColor(1, 1.0),
@@ -592,6 +571,40 @@ export class FeatherGrid extends Widget {
592571
};
593572
}
594573

574+
public updateGridStyle() {
575+
this._updateHeaderRenderer();
576+
577+
if (!this._defaultRendererSet) {
578+
this._defaultRenderer = new TextRenderer({
579+
font: '12px sans-serif',
580+
textColor: Theme.getFontColor(),
581+
backgroundColor: Theme.getBackgroundColor(),
582+
horizontalAlignment: 'left',
583+
verticalAlignment: 'center',
584+
});
585+
}
586+
587+
this._rowHeaderRenderer = new TextRenderer({
588+
textColor: Theme.getFontColor(1),
589+
backgroundColor: Theme.getBackgroundColor(2),
590+
horizontalAlignment: 'center',
591+
verticalAlignment: 'center',
592+
});
593+
594+
this._columnHeaderRenderer = new HeaderRenderer({
595+
textOptions: {
596+
textColor: Theme.getFontColor(1),
597+
backgroundColor: Theme.getBackgroundColor(2),
598+
horizontalAlignment: 'left',
599+
verticalAlignment: 'center',
600+
},
601+
isLightTheme: this._isLightTheme,
602+
grid: this.grid,
603+
});
604+
605+
this.setGridStyle();
606+
}
607+
595608
copyToClipboard(): void {
596609
const grid = <DataGrid>(<unknown>this);
597610
// Fetch the data model.
@@ -1014,6 +1027,7 @@ export class FeatherGrid extends Widget {
10141027
private _cellClicked = new Signal<this, FeatherGrid.ICellClickedEvent>(this);
10151028
private _columnsResized = new Signal<this, void>(this);
10161029
private _isLightTheme = true;
1030+
backboneModel: BackBoneModel;
10171031
}
10181032

10191033
/**

0 commit comments

Comments
 (0)