Search text in grid

Hello !

Please tell me how can I find first occurrence of the inserted text into all the columns of the grid.

In case the text is found, I want the entire row to be selected even the selection is on another page of the grid.

Otherwise a message must tell "the text is not found !

Thank you very much !


The razor page file is attached.

@page "/test"

@using Syncfusion.Blazor.Grids

@using Syncfusion.Blazor.Inputs


<h2>Test : Search in grid </h2>

<h3> Please tell me how can I search first occurrence of the inserted text into all the columns of the grid</h3>

<h3> In case the text is found, I want the entire row to be selected </h3>

<h3> Otherwise a message must tell "the text is not found !"</h3>

<SfTextBox Value="@TextToSearch" Placeholder="Insert text..."></SfTextBox>

<button @onclick="@SearchTextInGrid">Search Text in Grid</button>

<SfGrid DataSource="@Orders"></SfGrid>

@code{

    public List<Order> Orders { get; set; }

    protected override void OnInitialized()

    {

        Orders = Enumerable.Range(1, 75).Select(x => new Order()

        {

            OrderID = 1000 + x,

            CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],

            Freight = 2.1 * x,

            OrderDate = DateTime.Now.AddDays(-x),

        }).ToList();

    }

    public class Order

    {

        public int? OrderID { get; set; }

        public string CustomerID { get; set; }

        public DateTime? OrderDate { get; set; }

        public double? Freight { get; set; }

    }

    public string TextToSearch { get; set; } = "";

    public void SearchTextInGrid()

    {

    }

}



3 Replies

VN Vignesh Natarajan Syncfusion Team November 8, 2021 09:57 AM UTC

Hi Laurentiu, 
 
Thanks for contacting Syncfusion support. 
 
Query: “Please tell me how can I find first occurrence of the inserted text into all the columns of the grid. 
 
We have analyzed your query and we would like to inform you that we have built in support to search through the column. Refer our online demo and UG documentation for your reference 
 
 
if you still want to perform the search on external action, kindly refer the below code example. We have achieved your requirement using SearchAsync() method of Grid. 
 
<SfTextBox @bind-Value="@TextToSearch" Placeholder="Insert text..."></SfTextBox> 
<button @onclick="@SearchTextInGrid">Search Text in Grid</button> 
<SfGrid @ref="Grid" DataSource="@Orders"></SfGrid> 
  
@code{ 
  
    public List<Order> Orders { getset; } 
    SfGrid<Order> Grid { getset; } 
    public string TextToSearch { getset; } = ""; 
    public void SearchTextInGrid() 
    { 
        if (TextToSearch != "") 
        { 
            Grid.SearchAsync(TextToSearch); 
        } 
        //show custom dialog here as per your requirement for no text found 
    } 
 
 
Please get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan  



LA Laurentiu November 8, 2021 08:47 PM UTC

Thank you for your help !

But I think you did not understand what I want...

I don't want to filter the grid based on the TextToSearch value.

I just want to search in every column of the grid the first occurrence of the TextToSearch value. THE GRID MUST NOT BE FILTERED ! The data in the grid must remain as it was at the beginning.

I just want to select the first row of the grid which contains the TextToSearch value in any of the columns.

I want something like using a normal search in a file in Notepad with  CTRL+F.

Thank You Very Much !



VN Vignesh Natarajan Syncfusion Team November 9, 2021 11:54 AM UTC

Hi Laurentiu 
 
Thanks for the update. 
 
Query: ” I don't want to filter the grid,I just want to search in every column of the grid the first occurrence of the TextToSearch value. THE GRID MUST NOT BE FILTERED  
 
We have analyzed your query and currently we do not have support for your requirement. We have already logged an feature request task for this requirement “Provide support for find and highlight the searched text in DataGrid”. At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision and technological feasibility.  
  
You can now track the current status of this feature request from the below feedback page.    
 
    
You can also communicate with us regarding the open features any time using our above feedback report page. We do not have immediate plan to implement this feature and it will be included in any of our upcoming releases. Please cast your vote to make it count. So that we will prioritize the features for every release based on demands. 
 
Please let us know if you have any concerns. 
  
Regards,  
Vignesh Natarajan 


Loader.
Up arrow icon