Skip to content

Commit b07ee87

Browse files
author
JelteMX
committed
Merge branch 'master' of github.com:JelteMX/mendix-tree-table
2 parents 87bfa56 + 567e819 commit b07ee87

File tree

6 files changed

+53
-29
lines changed

6 files changed

+53
-29
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mxtreetable",
33
"widgetName": "MxTreeTable",
4-
"version": "2.0.4",
4+
"version": "2.0.5",
55
"description": "TreeTable widget",
66
"copyright": "Mendix 2019",
77
"author": "Jelte Lagendijk <jelte.lagendijk@mendix.com>",

src/MxTreeTable.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class MxTreeTable extends Component<MxTreeTableContainerProps> {
132132
uiRowIconPrefix: this.props.uiIconPrefix,
133133
uiRowIconAttr: this.props.uiRowIconAttr
134134
},
135+
expandFirstLevel: this.props.loadScenario === "all" && this.props.uiExpandFirstLevelWholeTree,
135136
validationMessages,
136137
validColumns: this.columnPropsValid,
137138
selectFirstOnSingle: this.props.selectSelectFirstOnSingle && this.props.selectMode === "single",
@@ -815,18 +816,22 @@ Your context object is of type "${contextEntity}". Please check the configuratio
815816
}
816817

817818
private _writeTableState(state: TableState): void {
819+
// We're doing this the dirty way instead of Object.assign because IE11 sucks
820+
const writeState = JSON.parse(JSON.stringify(state)) as TableState;
818821
const { stateManagementType, stateLocalStorageKey, stateLocalStorageType } = this.props;
819822
if (stateManagementType === "disabled" /* || stateManagementType === "mendix"*/) {
820823
return;
821824
}
822-
this.debug("writeTableState", state);
825+
this.debug("writeTableState", writeState);
823826
const key =
824-
stateLocalStorageKey !== "" ? `TreeTableState-${stateLocalStorageKey}` : `TreeTableState-${state.context}`;
825-
state.lastUpdate = +new Date();
827+
stateLocalStorageKey !== ""
828+
? `TreeTableState-${stateLocalStorageKey}`
829+
: `TreeTableState-${writeState.context}`;
830+
writeState.lastUpdate = +new Date();
826831
if (stateLocalStorageType === "session") {
827-
store.session.set(key, state);
832+
store.session.set(key, writeState);
828833
} else {
829-
store.local.set(key, state);
834+
store.local.set(key, writeState);
830835
}
831836
}
832837

src/MxTreeTable.xml

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -394,28 +394,36 @@ It should be a non-persistent entity (persistent is not permitted) with a refere
394394
*********************-->
395395

396396
<propertyGroup caption="UI">
397-
<property key="uiShowHeader" type="boolean" defaultValue="true">
398-
<caption>Show header</caption>
399-
<description>Make header row visible/invisible</description>
400-
</property>
401-
<property key="uiRowClassAttr" type="attribute" entityProperty="nodeEntity" required="false">
402-
<caption>Row Class Attribute</caption>
403-
<description>Attribute that will set an extra class on a row. This attribute should contain a valid css className, like 'mx-treeview-row'. This className can also be used in styling, where you would define a couple of classNames to set certain statuses and give each a color. This can be a calculated attribute, but keep in mind that performance might go down if you use that too much.</description>
404-
<attributeTypes>
405-
<attributeType name="String" />
406-
</attributeTypes>
407-
</property>
408-
<property key="uiRowIconAttr" type="attribute" entityProperty="nodeEntity" required="false">
409-
<caption>Icon Attribute</caption>
410-
<description>Attribute that will determine which icon to show in the first column of the row. Can be prefixed (see next)</description>
411-
<attributeTypes>
412-
<attributeType name="String" />
413-
</attributeTypes>
414-
</property>
415-
<property key="uiIconPrefix" type="string" required="false" defaultValue="glyphicon glyphicon-">
416-
<caption>Icon class prefix</caption>
417-
<description>When using icons in a row, it will use an &lt;i&gt; element with this className. When empty, it will use the standard 'glyphicon glyphicon-' prefix to use Bootstrap style elements. You can set your own icon prefixes here.</description>
418-
</property>
397+
<propertyGroup caption="General">
398+
<property key="uiShowHeader" type="boolean" defaultValue="true">
399+
<caption>Show header</caption>
400+
<description>Make header row visible/invisible</description>
401+
</property>
402+
<property key="uiRowClassAttr" type="attribute" entityProperty="nodeEntity" required="false">
403+
<caption>Row Class Attribute</caption>
404+
<description>Attribute that will set an extra class on a row. This attribute should contain a valid css className, like 'mx-treeview-row'. This className can also be used in styling, where you would define a couple of classNames to set certain statuses and give each a color. This can be a calculated attribute, but keep in mind that performance might go down if you use that too much.</description>
405+
<attributeTypes>
406+
<attributeType name="String" />
407+
</attributeTypes>
408+
</property>
409+
<property key="uiRowIconAttr" type="attribute" entityProperty="nodeEntity" required="false">
410+
<caption>Icon Attribute</caption>
411+
<description>Attribute that will determine which icon to show in the first column of the row. Can be prefixed (see next)</description>
412+
<attributeTypes>
413+
<attributeType name="String" />
414+
</attributeTypes>
415+
</property>
416+
<property key="uiIconPrefix" type="string" required="false" defaultValue="glyphicon glyphicon-">
417+
<caption>Icon class prefix</caption>
418+
<description>When using icons in a row, it will use an &lt;i&gt; element with this className. When empty, it will use the standard 'glyphicon glyphicon-' prefix to use Bootstrap style elements. You can set your own icon prefixes here.</description>
419+
</property>
420+
</propertyGroup>
421+
<propertyGroup caption="Scenario: Whole Tree">
422+
<property key="uiExpandFirstLevelWholeTree" type="boolean" defaultValue="false">
423+
<caption>Expand first level</caption>
424+
<description>Only works while loading the whole tree: Automatically expand the first level of the tree. Currently it is only possible to automatically expand the first level. This will be ignored if the user has already used state management before.</description>
425+
</property>
426+
</propertyGroup>
419427
</propertyGroup>
420428

421429
<!-- ****************

src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="MxTreeTable" version="2.0.4" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="MxTreeTable" version="2.0.5" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="MxTreeTable.xml"/>
66
</widgetFiles>

src/store/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface NodeStoreConstructorOptions {
4949
selectFirstOnSingle: boolean;
5050
validationMessages: ValidationMessage[];
5151
calculateInitialParents: boolean;
52+
expandFirstLevel: boolean;
5253
resetState: boolean;
5354
rowObjectMxProperties: RowObjectMxProperties;
5455

@@ -92,13 +93,15 @@ export class NodeStore {
9293
private needToCalculateInitialParents: boolean;
9394
private needToRestoreStateOnContextChange: boolean;
9495
private needToRestoreSelectFirst: boolean;
96+
private expandFirstLevel: boolean;
9597

9698
private reset: () => void;
9799
private resetColumns: (col: string) => void;
98100

99101
constructor({
100102
contextObject,
101103
dataResetOnContextChange,
104+
expandFirstLevel,
102105
columns,
103106
validColumns,
104107
selectFirstOnSingle,
@@ -119,6 +122,7 @@ export class NodeStore {
119122
this.dataResetOnContextChange =
120123
typeof dataResetOnContextChange !== "undefined" ? dataResetOnContextChange : false;
121124
this.columns = columns;
125+
this.expandFirstLevel = expandFirstLevel;
122126
this.validColumns = validColumns;
123127
this.selectFirstOnSingle = selectFirstOnSingle;
124128
this.needToRestoreSelectFirst = selectFirstOnSingle;
@@ -235,6 +239,12 @@ export class NodeStore {
235239
this.debug("store: setRowObjects get state: ", this.contextObject.getGuid());
236240
const initialTablesState = this.getInitialTableState(this.contextObject.getGuid());
237241

242+
// Expanding first level and safely writing this.
243+
if (typeof initialTablesState.lastUpdate === "undefined" && this.expandFirstLevel) {
244+
initialTablesState.expanded = rootObjectGuids;
245+
this.writeTableState(initialTablesState);
246+
}
247+
238248
// We need to filter out any that are not in the initial state
239249
initialState = {
240250
context: initialTablesState.context,

typings/MxTreeTableProps.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export interface MxTreeTableContainerProps extends CommonProps {
101101
uiRowClassAttr: string;
102102
uiRowIconAttr: string;
103103
uiIconPrefix: string;
104+
uiExpandFirstLevelWholeTree: boolean;
104105

105106
selectMode: SelectionMode;
106107
selectClickSelect: boolean;

0 commit comments

Comments
 (0)