How to get search result

Hi,
In My project I am using blazor grid component.In this I need help to achieve particular functionality.
I want to do is if user enter any text in search box and gets search result then I want to store this search result in particular list and if user clears the search I want to empty this assigned list.  

so is there any way to get this search result?

5 Replies

RS Renjith Singh Rajendran Syncfusion Team June 1, 2020 01:00 PM UTC

Hi Ashwini, 

Greetings from Syncfusion support. 

You can get the search key string in the Action events of Grid. By using this search string, you can form a predicate and use the PerformSearching method of DataOperations to fetch the search result in Grid. We have prepared a sample based on this requirement, please download the sample form the link below, 

Please refer and use as like the codes below, 

 
<Syncfusion.Blazor.Buttons.SfButton OnClick="Search">Get Search Result</Syncfusion.Blazor.Buttons.SfButton> 
 
    <SfGrid DataSource="@Orders" @ref="GridInstance" AllowPaging="true" Toolbar="@(new List<string>() { "Search" })"> 
        <GridEvents OnActionComplete="OnActionComplete" TValue="Order"></GridEvents> 
        ... 
    </SfGrid> 
 
    @code{ 
        public List<Order> Orders { getset; } 
        List<string> FieldNames = new List<string>(); 
        public List<Order> SearchResult { getset; } 
        List<SearchFilter> SearchPredicate = new List<SearchFilter>(); 
        public string SearchString = ""; 
        SfGrid<Order> GridInstance; 
        ... 
        public void OnActionComplete(ActionEventArgs<Order> args) 
        { 
            SearchString = args.SearchString;   //Get the search key string here 
        } 
        public async Task Search() 
        { 
            SearchPredicate = new List<SearchFilter>(); 
            FieldNames = await GridInstance.GetColumnFieldNames();   //Get the column field names 
            SearchPredicate.Add(new SearchFilter() 
            { 
                Fields = FieldNames, 
                Key = SearchString,              //Get value selected in datepicker 
                Operator = "contains", 
                IgnoreCase = true 
            }); 
            SearchResult = DataOperations.PerformSearching(Orders, SearchPredicate).ToList(); 
        } 
        ... 
    } 


Documentations :  
 
Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



AS Ashwini Shilvant June 1, 2020 07:59 PM UTC

Hi Renjith,
Thank you for quick response.
I downloaded project and run the code In this I am getting SearchString as empty string when I enter text in searchbox.
I also implement this logic in my project but I am getting SearchString as null when search  function is called.

Thanks.
 


RS Renjith Singh Rajendran Syncfusion Team June 2, 2020 10:05 AM UTC

Hi Ashwini, 

Thanks for your update. 

We tried to reproduce the reported problem with the sample attached from our previous update. But we are getting proper values of search key in SearchString. We have prepared a video demo to show the behavior. Please download the video from the link below, 
 
Please refer the screenshot below, 

 

And if you are still facing difficulties, then we need more details to further proceed on this. Kindly get back to us with the following details for better assistance. 
  1. Share the video demo showing the problem you are facing.
  2. Share the exact scenario/proper replication procedure.

And also you can fetch the SearchString by using the OnActionBegin event also as like the below code, 

 
<GridEvents OnActionBegin="OnActionBegin" OnActionComplete="OnActionComplete" TValue="Order"></GridEvents> 
 
public void OnActionBegin(ActionEventArgs<Order> args){    SearchString = args.SearchString;   //Get the search key string here}

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



AS Ashwini Shilvant June 3, 2020 08:08 PM UTC

Hi Renjith,

I have used "OnActionBegin" and it works.
I am getting that search string.

Due this I am able to achieve my functionality.
It's working as expected.

Thanks for your quick response. 


RS Renjith Singh Rajendran Syncfusion Team June 4, 2020 04:40 AM UTC

Hi Ashwini, 

Thanks for your update. 

We are glad to hear that the provided suggestion helped you in achieving your requirement. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 




Loader.
Up arrow icon