Select2
Dropdown — chọn 1 entity từ list nhỏ-tĩnh-tương-đối (status, loại). Load tất cả options khi render.
Source:
Core/Components/Select2.cs· ComType:Select2
Cấu hình
ComType: Select2
FieldName: StatusId
Reference: Status
DataSourceFilter: ?$filter=Active eq true # bắt buộc đủ "?$filter="
Field DB dùng
| Field | Vai trò |
|---|---|
Reference | Type của entity nguồn (vd Status, Country). |
RefName | Tên entity nguồn dạng string ("Status") — backup cho Reference. |
DataSourceFilter | OData querystring đủ ?$filter=... để filter list options. |
FormatData | String format hiển thị mỗi option (vd "{Code} - {Name}"). |
FocusSearch | True → auto focus search box bên trong dropdown khi mở. |
UpperCase | True → text option hiển thị uppercase. |
Events
Không fire event riêng — value sync vào entity.<FieldName> qua bind. Nếu cần phản ứng khi user đổi → dùng EditableComponent base event Change (tham khảo Component.Events JSON kèm method có signature (entity, newValue, oldValue, parent)).
Behavior
- Gọi
Client.GetRawList<Reference>(DataSourceFilter)1 lần khi render. - Lưu
id(int) của entity được chọn vàoentity.<FieldName>. - Display text từ field
Name/Labelcủa entity tham chiếu.
Khi nào dùng
✅ List option < 50, ổn định trong session (status, loại, vai trò).
❌ List > 50 → dùng SearchEntry có type-ahead.
Tip
DataSourceFilterphải bắt đầu bằng?$filter=. Xem Cấu hình UI → DataSourceFilter.- Để load lại options runtime (vd sau khi 1 option mới được thêm):
this.SetDataSourceSearchEntry("Name", newFilter)— xem Helpers thường dùng.