@syncfusion/ej2-dropdowns 34.1.33 → 34.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8144,6 +8144,7 @@ let DropDownTree = class DropDownTree extends Component {
8144
8144
  this.windowResizeContext = this.windowResize.bind(this);
8145
8145
  // Specifies if the checkAll method has been called
8146
8146
  this.isCheckAllCalled = false;
8147
+ this.isNodeChecked = false;
8147
8148
  this.isFromFilterChange = false;
8148
8149
  this.fallbackValue = [];
8149
8150
  }
@@ -10158,6 +10159,7 @@ let DropDownTree = class DropDownTree extends Component {
10158
10159
  onNodeChecked(args) {
10159
10160
  const eventArgs = this.getEventArgs(args);
10160
10161
  this.trigger('select', eventArgs);
10162
+ this.isNodeChecked = args.action === 'check';
10161
10163
  if (this.isFilteredData && args.action === 'uncheck') {
10162
10164
  const id = getValue('id', args.data[0]).toString();
10163
10165
  this.removeSelectedData(id, true);
@@ -10481,6 +10483,135 @@ let DropDownTree = class DropDownTree extends Component {
10481
10483
  }
10482
10484
  }
10483
10485
  }
10486
+ getFilteredTreeData() {
10487
+ return this.treeData;
10488
+ }
10489
+ getChildren(parentId, result) {
10490
+ const treeData = this.getFilteredTreeData();
10491
+ treeData.forEach((item) => {
10492
+ if (!isNullOrUndefined(item) && !isNullOrUndefined(item.pid) && !isNullOrUndefined(item.id) && item.pid.toString() === parentId.toString()) {
10493
+ const childId = item.id.toString();
10494
+ if (result.indexOf(childId) === -1) {
10495
+ result.push(childId);
10496
+ this.getChildren(childId, result);
10497
+ }
10498
+ }
10499
+ });
10500
+ }
10501
+ getDirectChildren(parentId) {
10502
+ return this.getFilteredTreeData()
10503
+ .filter((childNode) => !isNullOrUndefined(childNode) && !isNullOrUndefined(childNode.pid) && !isNullOrUndefined(childNode.id) && childNode.pid.toString() === parentId)
10504
+ .map((childNode) => childNode.id.toString());
10505
+ }
10506
+ updateFilteredAutoCheckValues() {
10507
+ const treeData = this.getFilteredTreeData();
10508
+ let currentValues = Array.isArray(this.value) ? this.value.map((item) => item.toString()) : [];
10509
+ const removeParent = (parentId) => {
10510
+ this.value = this.value.filter((value) => value.toString() !== parentId);
10511
+ };
10512
+ if (this.isNodeChecked) {
10513
+ this.treeObj.checkedNodes.map((item) => item.toString()).forEach((value) => {
10514
+ if (this.value.indexOf(value) === -1) {
10515
+ this.value.push(value);
10516
+ }
10517
+ });
10518
+ treeData.forEach((node) => {
10519
+ if (isNullOrUndefined(node) || isNullOrUndefined(node.id)) {
10520
+ return;
10521
+ }
10522
+ const parentId = node.id.toString();
10523
+ if (node.haschild && this.value.indexOf(parentId) !== -1) {
10524
+ const childValues = [];
10525
+ this.getChildren(parentId, childValues);
10526
+ if (this.value.indexOf(parentId) === -1) {
10527
+ this.value.push(parentId);
10528
+ }
10529
+ childValues.forEach((value) => {
10530
+ if (this.value.indexOf(value) === -1) {
10531
+ this.value.push(value);
10532
+ }
10533
+ });
10534
+ }
10535
+ currentValues = this.value.map((item) => item.toString());
10536
+ });
10537
+ treeData.forEach((node) => {
10538
+ if (isNullOrUndefined(node) || isNullOrUndefined(node.id)) {
10539
+ return;
10540
+ }
10541
+ if (!node.haschild) {
10542
+ return;
10543
+ }
10544
+ const parentId = node.id.toString();
10545
+ const directChildren = this.getDirectChildren(parentId);
10546
+ if (!directChildren.length) {
10547
+ return;
10548
+ }
10549
+ const allChildrenSelected = directChildren.every((childId) => this.value.indexOf(childId) !== -1);
10550
+ if (allChildrenSelected) {
10551
+ const childValues = [];
10552
+ this.getChildren(parentId, childValues);
10553
+ if (this.value.indexOf(parentId) === -1) {
10554
+ this.value.push(parentId);
10555
+ }
10556
+ childValues.forEach((value) => {
10557
+ if (this.value.indexOf(value) === -1) {
10558
+ this.value.push(value);
10559
+ }
10560
+ });
10561
+ }
10562
+ else {
10563
+ removeParent(parentId);
10564
+ }
10565
+ currentValues = this.value.map((item) => item.toString());
10566
+ });
10567
+ this.selectedData.forEach((item) => {
10568
+ const value = getValue(this.treeSettings.loadOnDemand ? this.fields.value : 'id', item).toString();
10569
+ if (this.value.indexOf(value) === -1) {
10570
+ this.selectedData = this.selectedData.filter((data) => getValue(this.treeSettings.loadOnDemand ? this.fields.value : 'id', data).toString() !== value);
10571
+ }
10572
+ });
10573
+ return;
10574
+ }
10575
+ const removeValues = [];
10576
+ treeData.forEach((node) => {
10577
+ if (isNullOrUndefined(node.id)) {
10578
+ return;
10579
+ }
10580
+ if (!node.haschild) {
10581
+ return;
10582
+ }
10583
+ const parentId = node.id.toString();
10584
+ if (currentValues.indexOf(parentId) === -1) {
10585
+ const childValues = [];
10586
+ this.getChildren(parentId, childValues);
10587
+ if (childValues.some((child) => currentValues.indexOf(child) !== -1)) {
10588
+ removeValues.push(...childValues);
10589
+ }
10590
+ }
10591
+ });
10592
+ if (removeValues.length) {
10593
+ this.value = this.value.filter((value) => removeValues.indexOf(value.toString()) === -1);
10594
+ currentValues = this.value.map((item) => item.toString());
10595
+ }
10596
+ treeData.forEach((node) => {
10597
+ if (isNullOrUndefined(node) || isNullOrUndefined(node.id)) {
10598
+ return;
10599
+ }
10600
+ if (!node.haschild) {
10601
+ return;
10602
+ }
10603
+ const parentId = node.id.toString();
10604
+ if (currentValues.indexOf(parentId) === -1) {
10605
+ return;
10606
+ }
10607
+ const hasDirectChild = treeData.some((childNode) => !isNullOrUndefined(childNode) && !isNullOrUndefined(childNode.pid) && !isNullOrUndefined(childNode.id) && childNode.pid.toString() === parentId &&
10608
+ currentValues.indexOf(childNode.id.toString()) !== -1);
10609
+ if (!hasDirectChild) {
10610
+ removeParent(parentId);
10611
+ currentValues = this.value.map((item) => item.toString());
10612
+ }
10613
+ });
10614
+ }
10484
10615
  updateSelectedValues() {
10485
10616
  this.dataValue = '';
10486
10617
  let temp;
@@ -10495,6 +10626,9 @@ let DropDownTree = class DropDownTree extends Component {
10495
10626
  if (!this.isFilteredData) {
10496
10627
  this.selectedData = [];
10497
10628
  }
10629
+ if (this.treeSettings.autoCheck && this.isFilteredData && !isNullOrUndefined(this.value)) {
10630
+ this.updateFilteredAutoCheckValues();
10631
+ }
10498
10632
  if (!isNullOrUndefined(this.value)) {
10499
10633
  const compiledString = this.initializeValueTemplate();
10500
10634
  for (let i = 0, len = this.value.length; i < len; i++) {
@@ -13467,6 +13601,7 @@ let MultiSelect = class MultiSelect extends DropDownBase {
13467
13601
  this.isBlurDispatching = false;
13468
13602
  this.isFilterPrevented = false;
13469
13603
  this.isFilteringAction = false;
13604
+ this.isPropertyChanged = false;
13470
13605
  this.isValidKey = false;
13471
13606
  this.selectAllEventData = [];
13472
13607
  this.selectAllEventEle = [];
@@ -14173,7 +14308,12 @@ let MultiSelect = class MultiSelect extends DropDownBase {
14173
14308
  }
14174
14309
  }
14175
14310
  else if (!(this.dataSource instanceof DataManager)) {
14176
- this.initialValueUpdate();
14311
+ if (!this.isRemoveSelection) {
14312
+ this.initialValueUpdate(this.listData, true);
14313
+ }
14314
+ else {
14315
+ this.initialValueUpdate();
14316
+ }
14177
14317
  }
14178
14318
  this.initialUpdate();
14179
14319
  this.refreshPlaceHolder();
@@ -17487,6 +17627,33 @@ let MultiSelect = class MultiSelect extends DropDownBase {
17487
17627
  this.unwireListEvents();
17488
17628
  this.wireListEvents();
17489
17629
  }
17630
+ getTextByValueFromDataSource(value) {
17631
+ const dataSource = this.dataSource;
17632
+ if (isNullOrUndefined(dataSource) || !dataSource.length) {
17633
+ return null;
17634
+ }
17635
+ if (this.isPrimitiveData) {
17636
+ for (let i = 0; i < dataSource.length; i++) {
17637
+ if (dataSource[i] === value) {
17638
+ return dataSource[i];
17639
+ }
17640
+ }
17641
+ return null;
17642
+ }
17643
+ const fields = this.fields;
17644
+ const valueField = fields.value ? fields.value : 'value';
17645
+ const textField = fields.text ? fields.text : 'text';
17646
+ for (let i = 0; i < dataSource.length; i++) {
17647
+ const item = dataSource[i];
17648
+ if (!isNullOrUndefined(item) && getValue(valueField, item) === value) {
17649
+ const resolvedText = getValue(textField, item);
17650
+ if (!isNullOrUndefined(resolvedText)) {
17651
+ return resolvedText;
17652
+ }
17653
+ }
17654
+ }
17655
+ return null;
17656
+ }
17490
17657
  initialValueUpdate(listItems, isInitialVirtualData, isInitialRender) {
17491
17658
  if (this.list) {
17492
17659
  let text;
@@ -17536,6 +17703,10 @@ let MultiSelect = class MultiSelect extends DropDownBase {
17536
17703
  }
17537
17704
  }
17538
17705
  }
17706
+ if (this.isPropertyChanged && isNullOrUndefined(text) && !this.allowCustomValue &&
17707
+ !(this.dataSource instanceof DataManager)) {
17708
+ text = this.getTextByValueFromDataSource(value);
17709
+ }
17539
17710
  if ((isNullOrUndefined(text) && this.allowCustomValue) &&
17540
17711
  ((!(this.dataSource instanceof DataManager)) ||
17541
17712
  (this.dataSource instanceof DataManager && isInitialVirtualData))) {
@@ -19164,6 +19335,7 @@ let MultiSelect = class MultiSelect extends DropDownBase {
19164
19335
  * @returns {void}
19165
19336
  */
19166
19337
  onPropertyChanged(newProp, oldProp) {
19338
+ this.isPropertyChanged = true;
19167
19339
  if (newProp.dataSource && !isNullOrUndefined(Object.keys(newProp.dataSource))
19168
19340
  || newProp.query && !isNullOrUndefined(Object.keys(newProp.query))) {
19169
19341
  this.mainList = null;
@@ -19335,6 +19507,7 @@ let MultiSelect = class MultiSelect extends DropDownBase {
19335
19507
  break;
19336
19508
  }
19337
19509
  }
19510
+ this.isPropertyChanged = false;
19338
19511
  }
19339
19512
  reInitializePoup() {
19340
19513
  if (this.popupObj) {