1) Test
a) test1
b) test2
b.1) Hello
b.2) Ram
2) Test Data
a) Demo
b) dummy
b.1) Cup
b.2) Plate
3) Dummy
a) test11
b) test22
b.1) Hello
b.2) Ram1
If we search text "Hello" then data should looks like below
1) Test
b) test2
b.1) Hello
3) Dummy
b) test22
b.1) Hello


Vishal JoshiRank #377 · 6.7K reputationPosted Nov 20, 2023, 3:42 AM EST
To search a hierarchical DataTable recursively, you can:
You can also apply searching to a specific column in DataTables through the column().search() method.
Please share DB and code details to get clear idea of expected solution.
Nimish SaxenaRank #2,279 · 618 reputationPosted Nov 20, 2023, 4:10 AM EST
If I seach "Probation" text then data should be show like Criminal Record->Case Name->Disposition Records->Probation.
i am usng datatable.js
Chris LoveRank #332 · 7.5K reputationPosted Nov 20, 2023, 3:10 PM EST
Hello,
To implement a hierarchical search in a DataTable within an ASP.NET Core application, you could leverage the concept of filtering based on a tree traversal algorithm. Since you're looking to filter the structure and retain the hierarchy, you might consider creating a recursive method that traverses the hierarchy and selectively includes nodes that match the search term.
Here's a high-level example of how you could implement this in C#:
public class Node { public string Key { get; set; } public string Value { get; set; } public List Children { get; set; } = new List(); // Recursive search function public Node Search(string searchTerm) { Node result = null; if (this.Value.Contains(searchTerm)) { result = new Node { Key = this.Key, Value = this.Value }; // No need to search children if the current node matches } else { foreach (var child in Children) { var searchResult = child.Search(searchTerm); if (searchResult != null) { if (result == null) { result = new Node { Key = this.Key }; } result.Children.Add(searchResult); } } } return result; } } // Usage var root = /* Your tree structure here */; var filteredRoot = root.Search("Hello"); // Convert 'filteredRoot' to the desired format for displayThis recursive function will return a new
Nodecontaining only the hierarchy that includes the search term "Hello". You will need to build your tree structure using theNodeclass.The filtering logic is handled within the
Searchmethod, which checks the current node and recursively its children for the search term. Child nodes are only included in the result if they or their descendants match the search term.I hope this helps! Let me know if you have further questions or if you need assistance with a specific part of the implementation.
Sam HobbsRank #107 · 20.5K reputationPosted Nov 20, 2023, 4:59 PM EST
Search for articles about self-referencing tables and hierarchical tables. Those are two names of the same thing, there are other names that are sometimes used but I forget the others. The articles will explain how to arrange the data such that each item has a reference to the parent.
You also want an index on the text, such as Hello in your example. Then to do the search you describe, search for items with the text and for each result, just walk up the hierarchy and then show the hierarchy from the top down. No need to do the search yourself and walk every existing hierarchy.