How can I get the number of search results?

A simple question.
I want to display the number of results from search in sfdatagrid .
How can I get the number of search results?

7 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team June 11, 2021 12:27 PM UTC

Hi nam ki hun, 

Thanks for contacting Syncfusion support.  

You can achieve your requirement to get the number of matched items by creating a custom SearchController and introducing a property as MatchCount as shown in the following code example.  

Code example :  

this.sfDataGrid1.SearchController.Search(this.textBox1.Text); 
 
int matchCount = 0; 
 
foreach (var item in this.sfDataGrid1.View.Records) 
{ 
     if (!item.IsRecords) 
         continue; 
 
     var data = (item as RecordEntry).Data; 
     foreach (var column in this.sfDataGrid1.Columns) 
     { 
         var cellValue = this.sfDataGrid1.View.GetPropertyAccessProvider().GetFormattedValue(data, column.MappingName).ToString(); 
 
         List<int> matchList = Regex.Matches(cellValue, this.sfDataGrid1.SearchController.SearchText, this.sfDataGrid1.SearchController.AllowCaseSensitiveSearch ? RegexOptions.None : RegexOptions.IgnoreCase) 
                              .Cast<Match>() 
                              .Select(s => s.Index).ToList(); 
 
 
         if (matchList.Count > 0) 
             matchCount++; 
     } 
} 
 
label1.Text = "Match Count = " + matchCount; 


Please let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 


Marked as answer

NK nam ki hun June 14, 2021 08:18 AM UTC

It's completely resolved.
Thank you.


MA Mohanram Anbukkarasu Syncfusion Team June 15, 2021 05:26 AM UTC

Hi nam ki hun, 

Thanks for the update.   

We are glad to know that the provided solution worked at your end. Please let us know if you require further assistance from us. We are happy to help you.   

Regards,  
Mohanram A. 



NK nam ki hun June 24, 2021 03:45 AM UTC

I got what I wanted with your help.

Thank you.


But the more data in sfdatagrid, the slower your code.

On the other hand, the search function of sfdatagrid is processed immediately.

So in the end I can't use your code.

Do you have any plans to put count in sfdatagrid's SearchController?



MA Mohanram Anbukkarasu Syncfusion Team June 25, 2021 11:53 AM UTC

Hi nam ki hun, 

Thanks for the update. 

We regret to inform you that it is not possible to provide count support for SearchController. Based on our implementation we will highlight only the cells which are in the view that matches the search text. But your requirement is to get count of all the possible matches from all the records. So the workaround we have provided in our previous update is the only possible way to achieve your requirement. Please let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 



NK nam ki hun June 28, 2021 07:56 AM UTC

Yes.

Your advice has helped me a lot.

Thank you.


Regards,

Ki Hun.



MA Mohanram Anbukkarasu Syncfusion Team June 29, 2021 05:19 AM UTC

Hi nam ki hun, 

Thanks for the update.  

Please let us know if you require any other assistance from us. We are happy to help you.  

Regards, 
Mohanram A. 


Loader.
Up arrow icon