Expanding Groups in SfDataGrid
Hi
Is it possible to expand only those groups in SfDataGRid GroupView where search function finds matching text within columns in grid?
For example, I want to search for string "01" in my grid . I expand all columns and have something like this
But I want to get this
As it is written (in violet), I want that group to be collapsed.
To see expanded only those grids where there is matching.
Thank you
Sabian
Hi Sabian,
Your
requirement is to expand only those groups that match the searched text
while expanding all groups. We can apply a filter for the text you want to
search. Kindly check if this solution meets your requirement.
We
have prepared a sample based on your requirement. Please review it and let us
know if it satisfies your needs or if you have any concerns.
Kindly refer the following code snippets.
|
private void textBox1_TextChanged(object sender, EventArgs e) { this.sfDataGrid1.SearchController.Search((sender as TextBox).Text); this.sfDataGrid1.SearchController.AllowFiltering = true; } |
Output :
Attachment: SfDataGrid_ExpandGroups_d1ba9cee.zip
Hi Dhivyabharathi Dakshinamurthy
For quick finding and displaying wanted data in SfDataGrid with GroupView I tried two methods. One was filtering and the other was search function. First, I used filter function based on your examples on Syncfusion internet sight. Function filtered data in grid where filter condition is matched. Than I used ExpandAll function to see data in grid.
But I want, when I press some Button (or press Enter within TextBox) to search SfDataGrid (content of TextBox) and see all groups in GroupView. Those groups where TextBox matches the content (or part of it) of the cells to be expanded (all levels) and the other groups where is no match in grid to stay collapsed.
In your example if I type "London" in textbox I want to see this
If there more ShipCity "London" in other OrderID or CustomerID I want that group to be expanded like OrderID: 1004 and CustomerID: AROUT is.
I am using vb.net (with Framework 4.8.1) so, please if your examples can be written in vb.net.
Thank you
Regards,
Sabian
Hi Sabian,
We are currently analyzing your reported scenario. We need time to validate the scenario, we will provide an update on or before June 14, 2024.
Hi Sabian,
We are currently analyzing your reported scenario. We need more time to validate the scenario, we will provide an update on or before June 19, 2024.
Hi Sabian,
We
regret the inconvenience.
To achieve your requirement, we are facing complexities in expanding the particular record. We need more time to validate the scenario and will provide an update on or before June 21, 2024.
Hi Sabian,
Your requirement is To expand only those groups that match the searched text.
This can be achieved by use to retrieve the groups. Based on the group,
retrieve the row data. with columns and row data, get the cell value using
GetPropertyAccessProvider. Compare the cell value with the search text in the
textbox, and then expand the groupitem based on the condition.
For your reference, we have attached the user guide link for handling grouping
support. Additionally, we have included a sample and a video reference for you
to review.
Please refer the code snippet:
|
Private Sub textBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles textBox1.TextChanged
Dim group = Me.sfDataGrid1.View.TopLevelGroup.Groups Dim searchText As String = (TryCast(sender, TextBox)).Text.ToLower() Dim columnDescriptionCount =sfDataGrid1.GroupColumnDescriptions.Count For Each groupItem In group For Each item3 In groupItem.Records For Each column In sfDataGrid1.Columns
Dim cellValue As String = Me.sfDataGrid1.View.GetPropertyAccessProvider().GetValue(item3.Data, column.MappingName).ToString() If Not String.IsNullOrEmpty(searchText) AndAlso cellValue.ToLower().Contains(searchText) Then groupItem.IsExpanded = True Exit For Else groupItem.IsExpanded = False End If Next column Next item3
Next groupItem sfDataGrid1.View.Refresh()
End Sub |
Regards,
Santhosh.G
Attachment: Sample_1b3ad9e0.zip
Hi Santhosh.G,
I ran your sample code, and it works great. I also added some code to mark found data.
I tried to group data on 3- levels and search for typed text but program stopped working.
For example, I grouped data like this (3- levels):
- First by column "OrderID" (this is first level)
- Then by column "CustomerID" (this is second level)
- Then by column "Country" (this is third level)
I am also sending video what I have tried to do.
Can you please, rewrite code to work on 3- levels grouping data and to search text only in predefined columns.
Regards,
Sabian
Attachment: Select_text_in_SfDataGrid_a57797cc.zip
Hi Sabian Sirius,
Based on the requirements, I modified the sample for multilevel grouping. I have attached the sample and a video reference for your review. Please take a look at it.
Regards,
Santhosh.G
Attachment: Sample_cf0a7c34.zip
Hi Santhosh.G,
I implemented your code in my application, and everything worked as I wanted. I made some modifications because in my application grid within the group has more than one row but based on your sample I managed to solve that issue.
I have attached a video to show how it works.
Thank you very much for the solution and spent time on my question.
Best regards,
Sabian
Attachment: Expanding_SfDataGrid__implemented_555981d1.zip
Hi Sabian Sirius,
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help.
Regards,
Santhosh.G
- 10 Replies
- 4 Participants
- Marked answer
-
SS Sabian Sirius
- Jun 9, 2024 03:47 PM UTC
- Jun 26, 2024 05:13 AM UTC