@(Html.EJ().Grid<crm.viewmodel.customervm> ("FlatGrid") //.Datasource((IEnumerable<object> )ViewBag.CustomerList)
|
@(Html.EJ().Grid<object>("Grid") }).ClientSideEvents(eve => { eve.ActionBegin("begin"); }) ) <script type="text/javascript">
function begin(args) { this.model.query.addParams("Type", "type"); this.model.query.addParams("IsActive", true); }
|
App.component.html
<ej-grid id="Grid" #grid [dataSource]="gridData" [allowPaging]="true" [allowSearching]="true" [toolbarSettings]="toolbarsettings">
<e-columns>
<e-column field="OrderID" headertext="Order ID" [isPrimaryKey]='true' width="90"></e-column>
<e-column field="CustomerID" headertext="Customer ID" width="80"></e-column>
. . .
</e-columns>
</ej-grid>
App.component.ts
export class GridComponent {
constructor() {
this.gridData = ej.DataManager({
url: "http://localhost:49339/api/Orders",
adaptor: new ej.WebApiAdaptor(),
crossDomain: true
});
this.toolbarsettings = { showToolbar: true, toolbarItems: ["search"] }
}
}
Serverside:-
public class ValuesController : ApiController
{
// GET api/<controller>
public PageResult<Order> Get(ODataQueryOptions opts)
{
if (opts.OrderBy != null)
results = opts.OrderBy.ApplyTo(results);
if (opts.Filter != null)
{
if (opts.Filter.RawValue.Contains("substring"))
{
// Seperating the value from the arguments of opts using spilt
string key = opts.Filter.RawValue.Split(new string[] { "'" }, StringSplitOptions.None)[1];
results = results.Where(fil => fil.CustomerID.Contains(key) || fil.EmployeeID.ToString().Contains(key) || fil.Freight.ToString().Contains(key) || fil.OrderID.ToString().Contains(key) || fil.ShipName.Contains(key) || fil.OrderDate.ToString().Contains(key) || fil.RequiredDate.ToString().Contains(key));
}
else
results = opts.Filter.ApplyTo(results, new ODataQuerySettings()).Cast<Order>();
}
}
|