smart-webcomponents-react
Version:
[](https://jqwidgets.com/license/)
6 lines (4 loc) • 3.83 kB
JavaScript
/* Smart UI v23.0.8 (2025-05-13)
Copyright (c) 2011-2024 jQWidgets.
License: https://htmlelements.com/license/ */ //
(()=>{"use strict";class e{_setRowProperty(e,t,o){const r=this,a=r.rowById[e];a&&(a[t]=o,r.stateSettings.autoSave&&r.stateSettings.current&&!r.stateSettings.loading&&r.saveState())}_setRowsProperty(e,t,o){const r=this;r._refreshLayout(),r._refreshRowHierarchy(!0);const a=r._recyclingRows;r.rows.canNotify=!1;for(let r=0;r<a.length;r++){const s=a[r];o&&-1===o.indexOf(s.id)||(s[e]=t,s.data&&void 0!==s.data[e]&&(s.data[e]=t))}r.rows.canNotify=!0,r.refresh()}expandRowsToGroupLevel(e){this._expandCollapseGroupsToLevel(!0,e)}_expandCollapseGroupsToLevel(e,t){const o=this;o._refreshLayout(),o._refreshRowHierarchy(!0);const r=o._recyclingRows;o.rows.canNotify=!1;for(let a=0;a<r.length;a++){const s=r[a];s.data.level<t&&(s.expanded=s.data.expanded=e,o.dataSource&&(e?o.dataSource._expandedRowIds[s.data.$.id]=!0:delete o.dataSource._expandedRowIds[s.data.$.id]))}o.rows.canNotify=!0,o.refresh()}_applyThreeStates(e){const t=this,o=e!==t.rowHierarchy;if(!t.rowHierarchy)return;const r=o?e.children:t.rowHierarchy.filter((e=>{if(0===e.level)return e}));let a=0,s=0;for(let d=0;d<r.length;d++){const c=r[d];e.checked&&(c.checked=!0),!1===c.leaf&&t._applyThreeStates(c),o&&(c.checked?a++:null===c.checked&&s++)}o&&(a===e.children.length?e.checked=!0:0===a&&0===s?e.checked=!1:t.checkBoxes.hasThreeStates?e.checked=null:e.checked=!1)}_hasThreeStates(e,t){const o=this;let r=e;for(e!==t&&(e.checked?e.checked=!1:e.checked=!0);r.parent;){const e=r.parent,t=e.children;let a=0,s=0;for(let e=0;e<t.length;e++)t[e].checked?a++:o.checkBoxes.hasThreeStates&&null===t[e].checked&&s++;a===e.children.length?e.checked=!0:0===a&&0===s?e.checked=!1:o.checkBoxes.hasThreeStates?e.checked=null:e.checked=!1,r=e}e.leaf||function e(t,o){const r=t.children;for(let t=0;t<r.length;t++){const a=r[t];a.checked=o,!1===a.leaf&&e(a,o)}}(e,e.checked)}_expandCollapseGroup(e,t){const o=this;if(!o.grouping.enabled||!o.rowHierarchy)return;e&&e.indexOf&&e.indexOf("Item")>=0&&(e=e.replace("Item",""));const r=(""+e).split(".");let a=o.rowHierarchy[r[0]];if(!a)return;const s=o.rows.canNotify;o.rows.canNotify=!1,null===t&&(t=!a.expanded),a.expanded=a.data.expanded=t,o._saveRowState(a.id,!a.expanded);for(let e=1;e<r.length&&(a=a.children[r[e]],a&&!a.leaf);e++)a.expanded=a.data.expanded=t;o.rows.canNotify=s,o._refresh(),o.stateSettings.autoSave&&o.stateSettings.current&&!o.stateSettings.loading&&o.saveState()}_saveRowState(e,t=!1){const o=this,r=o.rowById[e];if(r&&o.dataSource){if(t)return void delete o.dataSource._expandedRowIds[r.data.$.id];o.dataSource._expandedRowIds[r.data.$.id]=!0}}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),t._saveRowState(e))}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 o=t.rowById[e];o&&(o.expanded?o.expanded=!1:o.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),t._saveRowState(e,!0))}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})();