Hi,
I am trying to pass a search parameter from my grid to the contoller method. I have seen some search solution using the DataManager, however, they all
appear to be client side searching. Is there a way to pass the parameter to the controller method? Also is it possible to pass more than one parameter?
Below is my code, I want to perform a search for a person by firstname or lastname.
Thanks
// CSHTML
<ej-grid id="personsGrid" allow-resize-to-fit="true" allow-paging="true" allow-selection="true">
<e-datamanager url="PersonSearch" adaptor="WebApiAdaptor"></e-datamanager>
<e-edit-settings allow-searching="true"></e-edit-settings>
<e-page-settings enable-query-string="true"> </e-page-settings>
<e-toolbar-settings show-toolbar="true" toolbar-items='@new List<string> {"search"}' />
<e-columns>
<e-column field="Id" visible="false" is-primary-key="true" header-text="" text-align="Left"></e-column>
<e-column field="FirstName" allow-editing="false" header-text="First Name" text-align="Left"></e-column>
<e-column field="LastName" header-text="Last Name" text-align="Left"></e-column>
</e-columns>
</ej-grid>
@(Html.EJ().Grid<object>("Grid")
.Datasource(ds => ds.URL("/api/Orders").Adaptor(AdaptorType.WebApiAdaptor))
.AllowPaging() //Paging
.PageSettings(page => { page.PageSize(8); })
.EnableAltRow()
.ToolbarSettings(toolbar => { toolbar.ShowToolbar().ToolbarItems(items => { items.AddTool(ToolBarItems.Search); }); })
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(90).Add();
col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();
})
)
Serverside:-
public object Get()
{
List<OrdersView> ord = db.OrdersViews.ToList();
var queryString = HttpContext.Current.Request.QueryString;
int skip = Convert.ToInt32(queryString["$skip"]);
int take = Convert.ToInt32(queryString["$top"]);
string sort =queryString["$orderby"];
var filter = queryString["$filter"];
if (filter != null)
{
string key;
if (filter.Contains("substring")) //searching
{
key = filter.Split(new string[] { "'" }, StringSplitOptions.None)[1];
ord = ord.Where(fil => fil.CustomerID.Contains(key.ToUpper()) || fil.EmployeeID.ToString().Contains(key) || fil.Freight.ToString().Contains(key) || fil.OrderID.ToString().Contains(key) || fil.ShipCountry.Contains(key)).Distinct().ToList();
}
}
else
{
ord = ord.Skip(skip).Take(take).ToList();
}
var count = ord.Count;
return new {Items = ord, Count = count };
}
|
@(Html.EJ().Grid<object>("Grid")
.Datasource(ds => ds.URL("/api/Orders").Adaptor(AdaptorType.WebApiAdaptor))
.AllowPaging() //Paging
.Query("new ej.Query().addParams('data', 'Bern')")
.ToolbarSettings(toolbar => { toolbar.ShowToolbar().ToolbarItems(items => { items.AddTool(ToolBarItems.Search); }); })
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(90).Add();
col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();
})
Serverside:-
public ActionResult GetData(DataManager dm, string data)
{
}
|