-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsmart.grid.tree.js
6 lines (4 loc) · 3.38 KB
/
smart.grid.tree.js
1
2
3
4
5
6
/* Smart UI v15.2.0 (2023-04-20)
Copyright (c) 2011-2023 jQWidgets.
License: https://htmlelements.com/license/ */ //
(()=>{"use strict";class e{_setRowProperty(e,t,r){const o=this,s=o.rowById[e];s&&(s[t]=r,o.stateSettings.autoSave&&o.stateSettings.current&&!o.stateSettings.loading&&o.saveState())}_setRowsProperty(e,t,r){const o=this;o._refreshLayout(),o._refreshRowHierarchy(!0);const s=o._recyclingRows;o.rows.canNotify=!1;for(let o=0;o<s.length;o++){const a=s[o];r&&-1===r.indexOf(a.id)||(a[e]=t)}o.rows.canNotify=!0,o.refresh()}expandRowsToGroupLevel(e){this._expandCollapseGroupsToLevel(!0,e)}_expandCollapseGroupsToLevel(e,t){const r=this;r._refreshLayout(),r._refreshRowHierarchy(!0);const o=r._recyclingRows;r.rows.canNotify=!1;for(let s=0;s<o.length;s++){const a=o[s];a.data.level<t&&(a.expanded=a.data.expanded=e,r.dataSource&&(e?r.dataSource._expandedRowIds[a.data.$.id]=!0:delete r.dataSource._expandedRowIds[a.data.$.id]))}r.rows.canNotify=!0,r.refresh()}_applyThreeStates(e){const t=this,r=e!==t.rowHierarchy;if(!t.rowHierarchy)return;const o=r?e.children:t.rowHierarchy.filter((e=>{if(0===e.level)return e}));let s=0,a=0;for(let c=0;c<o.length;c++){const n=o[c];e.checked&&(n.checked=!0),!1===n.leaf&&t._applyThreeStates(n),r&&(n.checked?s++:null===n.checked&&a++)}r&&(s===e.children.length?e.checked=!0:0===s&&0===a?e.checked=!1:t.checkBoxes.hasThreeStates?e.checked=null:e.checked=!1)}_hasThreeStates(e,t){const r=this;let o=e;for(e!==t&&(e.checked?e.checked=!1:e.checked=!0);o.parent;){const e=o.parent,t=e.children;let s=0,a=0;for(let e=0;e<t.length;e++)t[e].checked?s++:r.checkBoxes.hasThreeStates&&null===t[e].checked&&a++;s===e.children.length?e.checked=!0:0===s&&0===a?e.checked=!1:r.checkBoxes.hasThreeStates?e.checked=null:e.checked=!1,o=e}e.leaf||function e(t,r){const o=t.children;for(let t=0;t<o.length;t++){const s=o[t];s.checked=r,!1===s.leaf&&e(s,r)}}(e,e.checked)}_expandCollapseGroup(e,t){const r=this;if(!r.grouping.enabled||!r.rowHierarchy)return;const o=(""+e).split(".");let s=r.rowHierarchy[o[0]];if(!s)return;const a=r.rows.canNotify;r.rows.canNotify=!1,null===t&&(t=!s.expanded),s.expanded=s.data.expanded=t;for(let e=1;e<o.length&&(s=s.children[o[e]],s&&!s.leaf);e++)s.expanded=s.data.expanded=t;r.rows.canNotify=a,r._refresh(),r.stateSettings.autoSave&&r.stateSettings.current&&!r.stateSettings.loading&&r.saveState()}expandRow(e){const t=this;t.grouping.enabled?t._expandCollapseGroup(e,!0):e&&Array.isArray(e)?t._setRowsProperty("expanded",!0,e):t._setRowProperty(e,"expanded",!0)}expandAllRows(){const e=this;e.grouping.enabled?e._expandCollapseGroupsToLevel(!0,99):e._setRowsProperty("expanded",!0)}collapseAllRows(){const e=this;e.grouping.enabled?e._expandCollapseGroupsToLevel(!1,99):e._setRowsProperty("expanded",!1)}toggleRow(e){const t=this;if(t.grouping.enabled)return void t._expandCollapseGroup(e,null);const r=t.rowById[e];r&&(r.expanded?r.expanded=!1:r.expanded=!0)}collapseRow(e){const t=this;t.grouping.enabled?t._expandCollapseGroup(e,!1):e&&Array.isArray(e)?t._setRowsProperty("expanded",!1,e):t._setRowProperty(e,"expanded",!1)}checkRow(e){const t=this;e&&Array.isArray(e)?t._setRowsProperty("checked",!0,e):t._setRowProperty(e,"checked",!0)}uncheckRow(e){const t=this;e&&Array.isArray(e)?t._setRowsProperty("checked",!1,e):t._setRowProperty(e,"checked",!1)}checkAllRows(){this._setRowsProperty("checked",!0)}uncheckAllRows(){this._setRowsProperty("checked",!1)}}Smart.Utilities.Grid.Tree=e})();