@progress/kendo-angular-grid
Version:
Kendo UI Grid for Angular - high performance data grid with paging, filtering, virtualization, CRUD, and more.
70 lines (69 loc) • 2.22 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { isPresent } from "../utils";
import { isCompositeFilterDescriptor } from "@progress/kendo-data-query";
const areDifferent = (a, b) => a.field !== b.field || a.operator !== b.operator || a.value !== b.value;
const isChanged = (a, b) => {
if (a.length !== b.length) {
return true;
}
for (let idx = 0, len = a.length; idx < len; idx++) {
const prev = a[idx];
const curr = b[idx];
if (isCompositeFilterDescriptor(prev)) {
if (diffFilters(prev, curr[idx])) {
return true;
}
}
else if (areDifferent(prev, curr)) {
return true;
}
}
return false;
};
const copyObject = (obj) => {
const result = {};
Object.assign(result, obj);
if (obj.constructor !== Object) {
const proto = obj.constructor.prototype;
Object.getOwnPropertyNames(proto).forEach((property) => {
if (property !== 'constructor' && property !== '__proto__' && property !== 'prototype' && proto.hasOwnProperty(property)) {
result[property] = obj[property];
}
});
}
return result;
};
const cloneFilter = (filter) => copyObject(filter);
/**
* @hidden
*/
export const cloneFilters = (filter) => {
if (!filter) {
return;
}
if (isCompositeFilterDescriptor(filter)) {
return {
filters: cloneFilters(filter.filters),
logic: filter.logic
};
}
else if (Array.isArray(filter)) {
return filter.map(cloneFilters);
}
return cloneFilter(filter);
};
/**
* @hidden
*/
export const diffFilters = (a, b) => {
if (isPresent(a) && !isPresent(b)) {
return true;
}
if (!isPresent(a) && isPresent(b)) {
return true;
}
return isPresent(a) && isPresent(b) && isChanged(a.filters, b.filters);
};