Articles in this section
Category / Section

Search the records in grid after immediate typing in search bar.

1 min read

This knowledge base explains the way to search the record value in grid after immediate typing in search box and how to cancel the searching after clicking the cancel icon in search box               

We can achieve this by binding keydown and keyup event for grid search text box in create event of grid.

HTML

<div id="Grid"></div>

 

JS

<script type="text/javascript">
            $(function () {
                $("#Grid").ejGrid({
                    dataSource: window.gridData,
                    allowPaging: true,
                    allowSearching: true,
                    create:"create",
                    toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Search] },
                   columns: [
                            { field: "OrderID", headerText: "Order ID", width: 75},
                            { field: "CustomerID", headerText: "Customer ID", width: 80 },
                            { field: "EmployeeID", headerText: "Employee ID", width: 75},
                            { field: "Freight", headerText: "Freight", width: 75, format: "{0:C}"},
                            { field: "ShipCity", headerText: "Ship City", width: 110}
                    ]
                });
            });
         </script>

 

RAZOR

@(Html.EJ().Grid<object>("Grid")
        .Datasource((IEnumerable<Object>)ViewBag.dataSource)
        .AllowPaging()
        .AllowSearching(true)
        .ToolbarSettings(toolbar =>{ toolbar.ShowToolbar(true).ToolbarItems(items      =>{items.AddTool(ToolBarItems.Search);});})
        .Columns(col =>
        {
            col.Field("OrderID").HeaderText("Order ID").Width(75).Add();
            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();
            col.Field("EmployeeID").HeaderText("Employee ID").Width(75).Add();
            col.Field("Freight").HeaderText("Freight").Width(75).Add();
            col.Field("ShipCity").HeaderText("Ship City").Width(110).Add();
        })
@(Html.EJ().Grid<object>("Grid")
        .Datasource((IEnumerable<Object>)ViewBag.dataSource)
        .AllowPaging()
        .AllowSearching(true)
        .ToolbarSettings(toolbar =>{ toolbar.ShowToolbar(true).ToolbarItems(items      =>{items.AddTool(ToolBarItems.Search);});})
        .Columns(col =>
        {
            col.Field("OrderID").HeaderText("Order ID").Width(75).Add();
            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();
            col.Field("EmployeeID").HeaderText("Employee ID").Width(75).Add();
            col.Field("Freight").HeaderText("Freight").Format("{0:C}").Width(80).Add();
            col.Field("ShipCity").HeaderText("Ship City").Width(110).Add();
        })
      .ClientSideEvents(eve=>eve.Create("create"))
    )

 

C#

namespace Sample.Controllers
  {
     public class GridController : Controller
      {
        public ActionResult GridFeatures()
         {
            ViewBag.datasource = new NorthwindDataContext().OrdersViews.ToList();
            return View();
         }
     }
}

 

ASPX

<ej:Grid ID="Grid" runat="server" AllowPaging="True" AllowSearching="True" >
         <Columns>
               <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" Width="75" />
               <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="80" />
               <ej:Column Field="EmployeeID" HeaderText="Employee ID"  Width="75" />
               <ej:Column Field="Freight" HeaderText="Freight"  Width="80" Format="{0:C}" />
                <ej:Column Field="ShipCity" HeaderText="Ship City" Width="110" />
         </Columns>
            <ToolbarSettings ShowToolbar="True" ToolbarItems="search"></ToolbarSettings>
            <ClientSideEvents Create="create" />
      </ej:Grid><ej:Grid ID="Grid" runat="server" AllowPaging="True">
    <toolbarsettings showtoolbar="True" toolbaritems="search"></toolbarsettings>
    <columns>
        <ej:column field="OrderID" headertext="Order ID" width=”75"></ej:column>
        <ej:column field="CustomerID" headertext="CustomerID" width=”80"></ej:column>
        <ej:column field="EmployeeID" headertext="EmployeeID" width="75"></ej:column>
        <ej:column field="Freight" headertext="Freight" width="80"></ej:column>
        <ej:column field="ShipCity" headertext="Ship City" width="110"></ej:column>
    </columns>
    <clientsideevents Create="create" />
</ej:Grid>

 

Immediate search can be done by using keydown, keyup event by passing the entered textbox value in the text boxvalue to to the search method of grid. Also uUsing clearSearching method it can be able towe can cancel clear the searching in grid while in the click event when clicking the cancel icon of search box.

<script>
            function create(args) {
                $('#Grid_search').bind('keydown keyup', function (e) {
                    var gridObj = $("#Grid").data("ejGrid");
                                   // Sends a search request to the Grid 
                    gridObj.search($(this).find(".e-gridsearchbar").val());
                });
                 $("#Grid_search").find('.e-cancel').on('click', function () {
                     var grid = $(".e-grid").data('ejGrid');
                     grid.clearSearching();   //clear the searched value when clicking cancel icon
                 })
               }
        </script>

 

 

C:\Users\Manisankar.durai\Desktop\sshot-1.png

Figure 1: Shows searcheding the grid records after entering the value in search box.

 

 

 

C:\Users\Manisankar.durai\Desktop\sshot-2.png

 

Figure 2: Sshows clear searchingentire grid records after clicking the cancel icon in search box.


Conclusion

I hope you enjoyed learning about how to Search the records in grid after immediate typing in search bar.

You can refer to our JavaScript Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.  You can also explore our  JavaScript Grid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied