Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the topic of How to retrieve searched records using a button click #3890

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions ej2-asp-core-mvc/code-snippet/grid/search/retrieve-records/razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div>
@Html.EJS().Button("getSearchedRecords").Content("Get Searched Records").Render()
</div>

@Html.EJS().Grid("grid").DataSource((IEnumerable<object>)ViewBag.datasource).Height("350px").Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").Width("160").Add();
col.Field("CustomerID").HeaderText("Customer ID").Width("170").Add();
col.Field("Freight").HeaderText("Freight").Width("170").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Format("C2").Add();
col.Field("OrderDate").HeaderText("Order Date").Width("170").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Format("yMd").Add();

}).Toolbar(new List<string>() { "Search" }).ActionComplete("actionComplete").Render()

<script>
var lastSearchString = '';
function actionComplete(args){
if (args.requestType === 'searching') {
lastSearchString = args.searchString;
}
}
document.getElementById('getSearchedRecords').addEventListener('click', () => {
if (lastSearchString) {
const gridInstance = document.getElementById('grid').ej2_instances[0];
const data = gridInstance.dataSource;
new ej.data.DataManager(data).executeQuery(new ej.data.Query().search(lastSearchString, [], undefined, true)).then((e) => {
console.log('Searched Records:', e.result);
});
}
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public IActionResult Index()
{
var orders = OrdersDetails.GetAllRecords();
ViewBag.datasource = orders;
return View();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div>
<button id="getSearchedRecords">Get Searched Records</button>
</div>

<ejs-grid id="grid" dataSource="@ViewBag.datasource" height="350px" toolbar="@(new List<string>() { "Search" })" actionComplete="actionComplete">
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" width="150"></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" format="C2" textAlign="Right" width="150"></e-grid-column>
<e-grid-column field="OrderDate" headerText="Order Date" format='yMd' textAlign="Right" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>

<script>
var lastSearchString = '';
function actionComplete(args){
if (args.requestType === 'searching') {
lastSearchString = args.searchString;
}
}
document.getElementById('getSearchedRecords').addEventListener('click', () => {
if (lastSearchString) {
const gridInstance = document.getElementById('grid').ej2_instances[0];
const data = gridInstance.dataSource;
new ej.data.DataManager(data).executeQuery(new ej.data.Query().search(lastSearchString, [], undefined, true)).then((e) => {
console.log('Searched Records:', e.result);
});
}
});
</script>
15 changes: 15 additions & 0 deletions ej2-asp-core-mvc/grid/EJ2_ASP.MVC/searching.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ The following example demonstrates how to clear the searched records using an ex

> You can also clear the searched records by using the clear icon within the search input field.

## How to retrieve searched records using a button click

To retrieve the searched records in a Syncfusion Grid on a button click, the search string from the toolbar search must be captured during the [actionComplete](../api/grid/#actionComplete) event, which triggers on searching. This captured search string can then be used with the DataManager's `executeQuery` method to filter and retrieve the corresponding data. Below is an example implementation:

{% tabs %}
{% highlight razor tabtitle="CSHTML" %}
{% include code-snippet/grid/search/retrieve-records/razor %}
{% endhighlight %}
{% highlight c# tabtitle="retrieve-records.cs" %}
{% include code-snippet/grid/search/retrieve-records/retrieve-records.cs %}
{% endhighlight %}
{% endtabs %}

![Retrieve searched records](images/search/retrieve-records.png)

## See also

* [How to perform search by using Wildcard and LIKE operator filter](https://ej2.syncfusion.com/aspnetmvc/documentation/grid/filtering/filtering#wildcard-and-like-operator-filter)
Expand Down
15 changes: 15 additions & 0 deletions ej2-asp-core-mvc/grid/EJ2_ASP.NETCORE/searching.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,21 @@ The following example demonstrates how to clear the searched records using an ex

> You can also clear the searched records by using the clear icon within the search input field.

## How to retrieve searched records using a button click

To retrieve the searched records in a Syncfusion Grid on a button click, the search string from the toolbar search must be captured during the [actionComplete](../api/grid/#actionComplete) event, which triggers on searching. This captured search string can then be used with the DataManager's `executeQuery` method to filter and retrieve the corresponding data. Below is an example implementation:

{% tabs %}
{% highlight cshtml tabtitle="CSHTML" %}
{% include code-snippet/grid/search/retrieve-records/tagHelper %}
{% endhighlight %}
{% highlight c# tabtitle="retrieve-records.cs" %}
{% include code-snippet/grid/search/retrieve-records/retrieve-records.cs %}
{% endhighlight %}
{% endtabs %}

![Retrieve searched records](images/search/retrieve-records.png)

## See also

* [How to perform search by using Wildcard and LIKE operator filter](https://ej2.syncfusion.com/aspnetcore/documentation/grid/filtering/filtering#wildcard-and-like-operator-filter)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.