igniteui-webcomponents
Version:
Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.
76 lines • 2.11 kB
JavaScript
import FilterDataOperation from '../operations/filter.js';
import GroupDataOperation from '../operations/group.js';
export class DataState {
get dataState() {
return this._dataState;
}
set searchTerm(value) {
if (this._searchTerm !== value) {
this._searchTerm = value;
this.invalidate();
}
}
get searchTerm() {
return this._searchTerm;
}
get filteringOptions() {
return this._host.filteringOptions;
}
get groupingOptions() {
return {
valueKey: this._host.valueKey,
displayKey: this._host.displayKey,
groupKey: this._host.groupKey,
direction: this._host.groupSorting,
};
}
get compareCollator() {
return this._compareCollator;
}
constructor(host) {
this._filtering = new FilterDataOperation();
this._grouping = new GroupDataOperation();
this._dataState = [];
this._searchTerm = '';
this._dirty = true;
this._host = host;
this._host.addController(this);
this._compareCollator = new Intl.Collator(this._host.locale);
}
hostUpdate() {
this._runPipelineIfDirty();
}
_markDirty() {
if (!this._dirty) {
this._dirty = true;
this._host.requestUpdate();
}
}
_runPipelineIfDirty() {
if (this._dirty) {
this._dataState = this._apply(Array.from(this._host.data));
this._dirty = false;
}
}
_index(data) {
return data.map((item, index) => ({
value: item,
header: false,
dataIndex: index,
}));
}
_apply(data) {
let records = this._index(data);
records = this._filtering.apply(records, this);
records = this._grouping.apply(records, this);
return records;
}
updateLocale(locale) {
this._compareCollator = new Intl.Collator(locale);
this._markDirty();
}
invalidate() {
this._markDirty();
}
}
//# sourceMappingURL=data.js.map