Skip to content

Commit

Permalink
feat: Allow overriding individual components
Browse files Browse the repository at this point in the history
  • Loading branch information
netchampfaris committed Sep 17, 2019
1 parent ad0e0b5 commit d92fc5e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/cellmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ export default class CellManager {
isHeader ? 'dt-cell--header' : '',
isHeader ? `dt-cell--header-${colIndex}` : '',
isFilter ? 'dt-cell--filter' : '',
isBodyCell && row.meta.isTreeNodeClose ? 'dt-cell--tree-close' : ''
isBodyCell && (row && row.meta.isTreeNodeClose) ? 'dt-cell--tree-close' : ''
].join(' ');

return `
Expand Down
40 changes: 32 additions & 8 deletions src/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import Style from './style';
import Keyboard from './keyboard';
import DEFAULT_OPTIONS from './defaults';

let defaultComponents = {
DataManager,
CellManager,
ColumnManager,
RowManager,
BodyRenderer,
Style,
Keyboard
};

class DataTable {
constructor(wrapper, options) {
DataTable.instances++;
Expand All @@ -23,14 +33,7 @@ class DataTable {

this.buildOptions(options);
this.prepare();

this.style = new Style(this);
this.keyboard = new Keyboard(this.wrapper);
this.datamanager = new DataManager(this.options);
this.rowmanager = new RowManager(this);
this.columnmanager = new ColumnManager(this);
this.cellmanager = new CellManager(this);
this.bodyRenderer = new BodyRenderer(this);
this.initializeComponents();

if (this.options.data) {
this.refresh();
Expand Down Expand Up @@ -66,6 +69,27 @@ class DataTable {
this.unfreeze();
}

initializeComponents() {
let components = Object.assign({}, defaultComponents, this.options.overrideComponents);
let {
Style,
Keyboard,
DataManager,
RowManager,
ColumnManager,
CellManager,
BodyRenderer
} = components;

this.style = new Style(this);
this.keyboard = new Keyboard(this.wrapper);
this.datamanager = new DataManager(this.options);
this.rowmanager = new RowManager(this);
this.columnmanager = new ColumnManager(this);
this.cellmanager = new CellManager(this);
this.bodyRenderer = new BodyRenderer(this);
}

prepareDom() {
this.wrapper.innerHTML = `
<div class="datatable" dir="${this.options.direction}">
Expand Down
3 changes: 3 additions & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export default {
desc: '↓',
none: ''
},
overrideComponents: {
// ColumnManager: CustomColumnManager
},
filterRows: filterRows,
freezeMessage: '',
getEditor: null,
Expand Down

0 comments on commit d92fc5e

Please sign in to comment.