Skip to content

Commit 6e4d842

Browse files
committed
DropDownList: move changes to lookup
1 parent c887ede commit 6e4d842

File tree

3 files changed

+68
-26
lines changed

3 files changed

+68
-26
lines changed

packages/devextreme/js/__internal/ui/drop_down_editor/m_drop_down_list.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,19 @@ const DropDownList = DropDownEditor.inherit({
603603
return this._searchValue().toString().length >= this.option('minSearchLength');
604604
},
605605

606+
_needClearFilter() {
607+
return this._canKeepDataSource() ? false : this._needPassDataSourceToList();
608+
},
609+
610+
_canKeepDataSource() {
611+
const isMinSearchLengthExceeded = this._isMinSearchLengthExceeded();
612+
return this._dataController.isLoaded()
613+
&& this.option('showDataBeforeSearch')
614+
&& this.option('minSearchLength')
615+
&& !isMinSearchLengthExceeded
616+
&& !this._isLastMinSearchLengthExceeded;
617+
},
618+
606619
_searchValue() {
607620
return this._input().val() || '';
608621
},
@@ -662,21 +675,11 @@ const DropDownList = DropDownEditor.inherit({
662675
}
663676
},
664677

665-
_presetListDataSource() {
666-
if (this._list && this._shouldRefreshDataSource()) {
667-
// this._dataSource.beginLoading();
668-
this._setListDataSource();
669-
// this._dataSource.endLoading();
670-
}
671-
},
672-
673678
_searchHandler(e, searchValue) {
674679
if (this._isTextCompositionInProgress()) {
675680
return;
676681
}
677682

678-
this._presetListDataSource();
679-
680683
if (!this._isMinSearchLengthExceeded()) {
681684
this._searchCanceled();
682685
return;
@@ -700,16 +703,7 @@ const DropDownList = DropDownEditor.inherit({
700703
if (this._needClearFilter()) {
701704
this._filterDataSource(null);
702705
}
703-
},
704-
705-
_needClearFilter(): boolean {
706-
const isMinSearchLengthExceeded = this._isMinSearchLengthExceeded();
707-
708-
return this._dataController.isLoaded()
709-
&& !this.option('showDataBeforeSearch')
710-
&& !!this.option('minSearchLength')
711-
&& !isMinSearchLengthExceeded
712-
&& this._isLastMinSearchLengthExceeded;
706+
this._refreshList();
713707
},
714708

715709
_searchDataSource(searchValue = this._searchValue()) {

packages/devextreme/js/__internal/ui/list/m_list.base.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,6 @@ export const ListBase = CollectionWidget.inherit({
564564
},
565565

566566
_dataSourceChangedHandler() {
567-
const isSearchCompleted = !this._dataSource?.isLoading();
568-
569-
if (!isSearchCompleted) {
570-
return;
571-
}
572-
573567
if (!this._shouldAppendItems() && hasWindow()) {
574568
this._scrollView && this._scrollView.scrollTo(0);
575569
}

packages/devextreme/js/__internal/ui/m_lookup.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,37 @@ const Lookup = DropDownList.inherit({
811811
}
812812
},
813813

814+
_presetListDataSource() {
815+
if (this._list && this._shouldRefreshDataSource()) {
816+
const forceLoading = !this._isLastMinSearchLengthExceeded;
817+
818+
if (forceLoading) {
819+
this._dataSource.beginLoading();
820+
}
821+
822+
this._setListDataSource();
823+
824+
if (forceLoading) {
825+
this._dataSource.endLoading();
826+
}
827+
}
828+
},
829+
830+
_searchHandler() {
831+
this._presetListDataSource();
832+
this.callBase();
833+
},
834+
835+
_needClearFilter(): boolean {
836+
const isMinSearchLengthExceeded = this._isMinSearchLengthExceeded();
837+
838+
return this._dataController.isLoaded()
839+
&& !this.option('showDataBeforeSearch')
840+
&& !!this.option('minSearchLength')
841+
&& !isMinSearchLengthExceeded
842+
&& this._isLastMinSearchLengthExceeded;
843+
},
844+
814845
_updateActiveDescendant() {
815846
this.callBase();
816847

@@ -987,6 +1018,29 @@ const Lookup = DropDownList.inherit({
9871018
this.callBase();
9881019
},
9891020

1021+
_renderList() {
1022+
this.callBase();
1023+
this._setListDataSourceChangedHandler();
1024+
},
1025+
1026+
_setListDataSourceChangedHandler() {
1027+
const defaultHandler = this._list._dataSourceChangedHandler.bind(this._list);
1028+
1029+
this._list._dataSourceChangedHandler = this._enrichListDataSourceChangeHandler(defaultHandler);
1030+
},
1031+
1032+
_enrichListDataSourceChangeHandler(defaultHandler) {
1033+
return (...args) => {
1034+
const isSearchCompleted = !this._getDataSource()?.isLoading();
1035+
1036+
if (!isSearchCompleted) {
1037+
return;
1038+
}
1039+
1040+
defaultHandler(...args);
1041+
};
1042+
},
1043+
9901044
_clean() {
9911045
this._$fieldWrapper.remove();
9921046
clearTimeout(this._hideOnParentScrollTimer);

0 commit comments

Comments
 (0)