Skip to content

Instantly share code, notes, and snippets.

@NickersF
Created October 3, 2022 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickersF/939eef9bb5617374f28ae1a7f426e2ba to your computer and use it in GitHub Desktop.
Save NickersF/939eef9bb5617374f28ae1a7f426e2ba to your computer and use it in GitHub Desktop.
Loops for filtering grid column menu aggregate counts and positions.
interface IColumnAggregateCount {
field: string;
aggregateCount: number;
}
let columnAggregateCountObjects = new Array<IColumnAggregateCount>();
let columnsWithActiveAggregates: string[] = [];
// This code may come in handy in the future. It enumerates aggregates on columns.
// Increment aggregate count column-wise
columnAggregateCountObjects.forEach((columnAggregateObject) => {
if (columnAggregateObject.field == field) {
columnAggregateObject.aggregateCount++;
}
});
// Get current aggregate count
columnAggregateCountObjects.forEach((columnAggregateObject) => {
if (columnAggregateObject.field == field) {
currAggregateCount = columnAggregateObject.aggregateCount;
}
});
// Get aggregates of other columns
columnAggregateCountObjects.forEach((columnAggregateObject) => {
if ((columnAggregateObject.field != field) && (columnAggregateObject.aggregateCount != 0)) {
console.log(columnAggregateObject);
}
});
// Count column names with active aggregates
columnAggregateCountObjects.forEach((columnAggregateObject) => {
if (columnAggregateObject.aggregateCount > 0) {
if (!columnsWithActiveAggregates.includes(columnAggregateObject.field)) {
columnsWithActiveAggregates.push(columnAggregateObject.field);
}
}
});
// Decrement aggregate count column-wise
columnAggregateCountObjects.forEach((columnAggregateObject) => {
if (columnAggregateObject.field == field) {
columnAggregateObject.aggregateCount--;
console.log(`Column (field): ${columnAggregateObject.field} | Column aggregate count: ${columnAggregateObject.aggregateCount}`);
}
});
columnsWithActiveAggregates.pop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment