33// See the LICENSE file in the project root for more information.
44// Maintainer: Argo Zhang([email protected] ) Website: https://www.blazor.zone 55
6+ using Microsoft . AspNetCore . Components . Web . Virtualization ;
67using Microsoft . Extensions . Localization ;
78
89namespace BootstrapBlazor . Components ;
@@ -97,6 +98,33 @@ public partial class AutoFill<TValue>
9798 [ Parameter ]
9899 public bool IsVirtualize { get ; set ; }
99100
101+ /// <summary>
102+ /// Gets or sets the row height for virtual scrolling. Default is 33.
103+ /// </summary>
104+ /// <remarks>Effective when <see cref="IsVirtualize"/> is set to true.</remarks>
105+ [ Parameter ]
106+ public float RowHeight { get ; set ; } = 33f ;
107+
108+ /// <summary>
109+ /// Gets or sets the overscan count for virtual scrolling. Default is 4.
110+ /// </summary>
111+ /// <remarks>Effective when <see cref="IsVirtualize"/> is set to true.</remarks>
112+ [ Parameter ]
113+ public int OverscanCount { get ; set ; } = 4 ;
114+
115+ /// <summary>
116+ /// Gets or sets the callback method for loading virtualized items.
117+ /// </summary>
118+ [ Parameter ]
119+ [ NotNull ]
120+ public Func < VirtualizeQueryOption , Task < QueryData < TValue > > > ? OnQueryAsync { get ; set ; }
121+
122+ /// <summary>
123+ /// Gets or sets whether the select component is clearable. Default is false.
124+ /// </summary>
125+ [ Parameter ]
126+ public bool IsClearable { get ; set ; }
127+
100128 [ Inject ]
101129 [ NotNull ]
102130 private IStringLocalizer < AutoComplete > ? Localizer { get ; set ; }
@@ -107,6 +135,9 @@ public partial class AutoFill<TValue>
107135
108136 private List < TValue > ? _filterItems ;
109137
138+ [ NotNull ]
139+ private Virtualize < TValue > ? _virtualizeElement = default ;
140+
110141 /// <summary>
111142 /// <inheritdoc/>
112143 /// </summary>
@@ -142,6 +173,34 @@ private async Task OnClickItem(TValue val)
142173
143174 private List < TValue > Rows => _filterItems ?? [ .. Items ] ;
144175
176+ private int _totalCount ;
177+ private TValue ? _itemsCache ;
178+ private ItemsProviderResult < TValue > _result ;
179+
180+ private async ValueTask < ItemsProviderResult < TValue > > LoadItems ( ItemsProviderRequest request )
181+ {
182+ // 有搜索条件时使用原生请求数量
183+ // 有总数时请求剩余数量
184+ var count = _totalCount == 0 ? request . Count : Math . Min ( request . Count , _totalCount - request . StartIndex ) ;
185+ var data = await OnQueryAsync ( new ( ) { StartIndex = request . StartIndex , Count = count } ) ;
186+
187+ _itemsCache = default ;
188+ _totalCount = data . TotalCount ;
189+ var items = data . Items ?? [ ] ;
190+ _result = new ItemsProviderResult < TValue > ( items , _totalCount ) ;
191+ return _result ;
192+ }
193+
194+ private List < TValue > GetVirtualItems ( )
195+ {
196+ var items = new List < TValue > ( ) ;
197+ if ( Items != null )
198+ {
199+ items . AddRange ( Items ) ;
200+ }
201+ return items ;
202+ }
203+
145204 /// <summary>
146205 /// Triggers the filter method.
147206 /// </summary>
0 commit comments