// a given cell or all cells in a column.
@Input() cellClassCallback: (row: any, col: GridColumn) => string;
+ // comma-separated list of fields to hide.
+ // This is less verbose than having to define an <eg-grid-column/>
+ // just to mark it hidden.
+ @Input() hideFields: string;
+
context: GridContext;
// These events are emitted from our grid-body component.
this.context.disableMultiSelect = this.disableMultiSelect === true;
this.context.rowFlairIsEnabled = this.rowFlairIsEnabled === true;
this.context.rowFlairCallback = this.rowFlairCallback;
+ if (this.hideFields) {
+ this.context.defaultHiddenFields = this.hideFields.split(',');
+ }
// TS doesn't seem to like: let foo = bar || () => '';
this.context.rowClassCallback =
isMultiSortable: boolean;
stockVisible: string[];
idl: IdlService;
+ defaultHiddenFields: string[];
constructor(idl: IdlService, idlClass?: string) {
this.idl = idl;
}
applyColumnSettings(conf: GridColumnPersistConf[]) {
- if (!conf || conf.length === 0) { return; }
+
+ if (!conf || conf.length === 0) {
+
+ // If no configuration is available, but we have a list of
+ // fields to hide by default, hide them.
+ if (this.defaultHiddenFields) {
+ this.defaultHiddenFields.forEach(name => {
+ const col = this.getColByName(name);
+ if (col) col.visible = false;
+ });
+ }
+
+ return;
+ }
const newCols = [];
rowFlairCallback: (row: any) => GridRowFlairEntry;
rowClassCallback: (row: any) => string;
cellClassCallback: (row: any, col: GridColumn) => string;
+ defaultHiddenFields: string[];
// Services injected by our grid component
idl: IdlService;
this.columnSet = new GridColumnSet(this.idl, this.idlClass);
this.columnSet.isSortable = this.isSortable === true;
this.columnSet.isMultiSortable = this.isMultiSortable === true;
- this.generateColumns();
+ this.columnSet.defaultHiddenFields = this.defaultHiddenFields;
}
// Load initial settings and data.
initData() {
- this.getColumnsConfig(this.persistKey)
- .then(conf => this.columnSet.applyColumnSettings(conf))
+
+ // run in timeout because we are modifying the state of the
+ // grid column header component mid-digest
+ setTimeout(() => this.generateColumns());
+
+ this.applyColumnsConfig()
.then(ok => this.dataSource.requestPage(this.pager))
.then(ok => this.listenToPager());
}
this.ignorePager();
}
+ applyColumnsConfig(): Promise<void> {
+ return this.getColumnsConfig(this.persistKey)
+ .then(conf => this.columnSet.applyColumnSettings(conf));
+ }
+
reload() {
// Give the UI time to settle before reloading grid data.
// This can help when data retrieval depends on a value
}
generateColumns() {
+ if (!this.columnSet.idlClass) { return; }
+
+ const pkeyField = this.idl.classes[this.columnSet.idlClass].pkey;
// generate columns for all non-virtual fields on the IDL class
- if (this.columnSet.idlClass) {
- this.idl.classes[this.columnSet.idlClass].fields.forEach(field => {
- if (field.virtual) { return; }
- const col = new GridColumn();
- col.name = field.name;
- col.label = field.label || field.name;
- col.idlFieldDef = field;
- col.datatype = field.datatype;
- if (field.name ===
- this.idl.classes[this.columnSet.idlClass].pkey) {
- col.isIndex = true;
- }
- this.columnSet.add(col);
- });
- }
+ this.idl.classes[this.columnSet.idlClass].fields
+ .filter(field => !field.virtual)
+ .forEach(field => {
+ const col = new GridColumn();
+ col.name = field.name;
+ col.label = field.label || field.name;
+ col.idlFieldDef = field;
+ col.datatype = field.datatype;
+ col.isIndex = (field.name === pkeyField);
+ this.columnSet.add(col);
+ });
}