In order to simplify the process, I am looking for a way to filter multiple properties of a parent-child array that may have multiple levels. This is specifically for an Open Source datagrid library that is utilized by hundreds of users.
The array consists of parent/children references, with each child having the potential to have its own children and so on. The tree structure can go as deep as necessary. Additionally, I need the ability to filter not only based on the property defining the tree structure but also on any other properties/columns within the array.
For example, consider the following array which represents a file explorer list:
const myFiles = [
{id: 11, file: "Music", parentId: null },
{id: 12, file: "mp3", parentId: 11 },
{id: 14, file: "pop", parentId: 12 },
{id: 15, file: "theme.mp3", dateModified: "2015-03-01", size: 85, parentId: 14, },
{id: 16, file: "rock", parentId: 12 },
{id: 17, file: "soft.mp3", dateModified: "2015-05-13", size: 98, parentId: 16, },
{id: 18, file: "else.txt", dateModified: "2015-03-03", size: 90, parentId: null, },
{id: 21, file: "Documents", parentId: null, },
{id: 2, file: "txt", parentId: 21 },
{id: 3, file: "todo.txt", dateModified: "2015-05-12", size: 0.7, parentId: 2, },
{id: 4, file: "pdf", parentId: 21 },
{id: 22, file: "map2.pdf", dateModified: "2015-05-21", size: 2.9, parentId: 4 },
{id: 5, file: "map.pdf", dateModified: "2015-05-21", size: 3.1, parentId: 4, },
{id: 6, file: "internet-bill.pdf", dateModified: "2015-05-12", size: 1.4, parentId: 4, },
{id: 7, file: "xls", parentId: 21 },
{id: 8, file: "compilation.xls", dateModified: "2014-10-02", size: 2.3, parentId: 7, },
{id: 9, file: "misc", parentId: 21 },
{id: 10, file: "something.txt", dateModified: "2015-02-26", size: 0.4, parentId: 9, }
]
Although this array appears flat, it actually represents a tree view structure displayed in a datagrid.
To address this, I have implemented a method to add a 'treeMap' array to each item, which represents the hierarchy of files. This allows filtering based on specific columns.
Here is the method that accomplishes this:
export function modifyDatasetToAddTreeMapping(items: any[], treeViewColumn: Column, dataView: any) {
// Implementation code here
}
Following the addition of the 'treeMap' arrays, the datagrid library's filter method can be used to implement filtering logic based on user-defined criteria.
If you are interested in accessing the complete implementation details or wish to contribute to enhancing this functionality, please refer to the provided links.