- Home
- Forum
- ASP.NET MVC
- Add autocomplete for grid search and autocomplete selected in the grid does not work
Add autocomplete for grid search and autocomplete selected in the grid does not work
Hello
I need help
1) Add autocomplete for grid search
2) The autocomplete selected in the grid does not work when performing dynamic calls on the server. The rest of everything works fine (sorting, filtering, searching)
screenshot: https://prnt.sc/fz6r16
[in controller]
public JsonResult GetDataCar(DataManager dm)
{
IEnumerable data1 = GetData();
DataOperations operation = new DataOperations();
if (dm.Search != null && dm.Search.Count > 0) //Searching
{
data1 = operation.PerformSearching(data1, dm.Search);
}
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
data1 = operation.PerformSorting(data1, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
data1 = operation.PerformWhereFilter(data1, dm.Where, dm.Where[0].Operator);
}
int count = data1.Cast<CarsList>().Count();
if (dm.Skip != 0)
{
data1 = operation.PerformSkip(data1, dm.Skip);
}
if (dm.Take != 0)
{
data1 = operation.PerformTake(data1, dm.Take);
}
return Json(new { result = data1, count = count }, JsonRequestBehavior.AllowGet);
}
[in view]
@(Html.EJ().Grid<object>("Grid")
.Datasource(ds => ds.URL(Url.Action("GetDataCar")).Adaptor(AdaptorType.UrlAdaptor))
.AllowSorting()
.AllowSearching()
.ToolbarSettings(toolbar => { toolbar.ShowToolbar().ToolbarItems(items => { items.AddTool(ToolBarItems.Search); }); })
.AllowPaging()
.PageSettings(page => page.PageSize(20).PageCount(5))
.AllowFiltering()
.FilterSettings(filter => { filter.FilterType(FilterType.Menu); })
.Columns(col =>
{
col.Field("text").HeaderText("text").TextAlign(TextAlign.Right).Add();
col.Field("company").HeaderText("company").TextAlign(TextAlign.Right).Add();
})
)
SIGN IN To post a reply.
5 Replies
TS
Thavasianand Sankaranarayanan
Syncfusion Team
July 24, 2017 12:51 PM UTC
Hi Andre,
Thanks for contacting Syncfusion support.
We have analyzed your query and we are able to reproduce the reported issue “Autcomplete search values return no suggestion to display” from our end with your given code example.
To avoid this issue, we need to check the condition with the RequiresCounts from the parameter of DataManager and return only data.
Refer the below code example.
|
public ActionResult DataSource(DataManager dm)
{
IEnumerable DataSource = new NorthwindDataContext().OrdersViews.ToList();
DataResult result = new DataResult();
DataOperations operation = new DataOperations();
result.result = DataSource;
---------
result.count = result.result.AsQueryable().Count();
if (dm.RequiresCounts)
return Json(result, JsonRequestBehavior.AllowGet);
else
return Json(result.result, JsonRequestBehavior.AllowGet); // return only data, when RequiresCounts is set as false
}
|
We have prepared a sample and it can be downloadable from the below location.
Sample: http://www.syncfusion.com/downloads/support/forum/131679/ze/SyncfusionMvcApplication123497751181.zip
If we misunderstood your query then please get back to us.
Regards,
Thavasianand S.
AN
Andre
July 25, 2017 06:20 AM UTC
Thanks for the quick response.
Everything works perfectly.
But one of the questions remained unanswered.
How do I add auto-complete for a table search?
TS
Thavasianand Sankaranarayanan
Syncfusion Team
July 26, 2017 01:25 PM UTC
Hi Andre,
Sorry for the inconvenience caused.
We have analyzed your query and we suspect that you want have external autocomplete search box for a particular column in Grid.
We have achieved the same by using the search() method of ejGrid control, with the external button click event.
Refer the below code example.
|
<div>
@{
Html.EJ()
.Autocomplete("selectCustomerID")
.EnableAutoFill(true)
.Datasource(ds => ds.URL("/Grid/DataSource").Adaptor(AdaptorType.UrlAdaptor))
.WatermarkText("Select a CustomerID")
.Query("ej.Query()").AutocompleteFields(af => af.Text("CustomerID")).Width("300")
.FilterType(FilterOperatorType.Contains)
.Render();
}
<input type="button" value="ClickToSearch" onclick="Searching()" />
</div>
@(Html.EJ().Grid<object>("FlatGrid")
---------
.AllowPaging() /*Paging Enabled*/
.AllowSearching()
.Columns(col =>
{
-------------
}))
</div>
<script type="text/javascript">
function Searching()
// Create a grid object.
var gridObj = $("#FlatGrid").ejGrid("instance");
// create a send request to the grid
gridObj.search($("#selectCustomerID").val())
}
</script>
|
We have prepared a sample and it can be downloadable from the below location.
Refer the help documentation.
Regards,
Thavasianand S.
AN
Andre
July 27, 2017 02:20 PM UTC
Thanks for the help, in my project I did exactly that. But I thought there might be some other way to implement this feature
TS
Thavasianand Sankaranarayanan
Syncfusion Team
July 28, 2017 03:25 PM UTC
Hi Andre,
We suggest you to use the search feature in the custom toolbar item of ejGrid control. We have render the ejAutocomplete box in the custom toolbar.
Refer the below code example.
|
[GridFeatures.cshtml]
@(Html.EJ().Grid<OrdersView>("FlatGrid")
.Datasource(ds => ds.URL("/Grid/DataSource").Adaptor(AdaptorType.UrlAdaptor))
---------
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar(true).CustomToolbarItems(new List<object>() { new Syncfusion.JavaScript.Models.CustomToolbarItem() { TemplateID = "#Search" }, new Syncfusion.JavaScript.Models.CustomToolbarItem() { TemplateID = "#button" } });
})
.AllowSearching()
.ClientSideEvents(cevent => cevent.ActionComplete("complete").ToolbarClick("toolbarclick"))
.Columns(col =>
{
--------
})
)
</div>
<script id="Search" type="text/x-jsrender">
<input />
</script>
<script id="button" type="text/x-jsrender">
<input type="button" value="ClearSearch" />
</script>
<script type="text/javascript">
function complete(args) {
var dataManager = ej.DataManager({ url: "/Grid/DataSource", adaptor: new ej.UrlAdaptor() });
$("#FlatGrid_Search input").ejAutocomplete({ dataSource: dataManager, fields: { text: "CustomerID" }, select: "searchingText" });
}
function toolbarclick(args) {
if (args.itemName != "Search") {
var gridObj = $("#FlatGrid").ejGrid('instance');
gridObj.clearSearching();
}
}
function searchingText(args) {
var gridObj = $("#FlatGrid").ejGrid('instance');
gridObj.search($("#FlatGrid_Search input").val());
}
</script>
|
We have prepared a sample and it can be downloadable from the below location.
For more information about custom toolbar items. Please refer the following knowledge base link.
Refer the help documentation.
Regards,
Thavasianand S.
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
AN Andre
- Jul 23, 2017 11:36 AM UTC
- Jul 28, 2017 03:25 PM UTC