| CSHTML: <ej-autocomplete id="AutoComplete" allow-sorting="true" sort-order="Ascending" > <e-datamanager id="DataAdaptor" adaptor="UrlAdaptor" url="Index/InlineSearch" /> <e-autocomplete-fields key="id" text="title" /> </ej-autocomplete> Controller: public JsonResult InlineSearch([FromBody]DataManager dm) { Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations(); lstResults.Add(new SearchResult() { Title = "ASTRO Company", ID = 1 }); lstResults.Add(new SearchResult() { Title = "AZTEC Company", ID = 2 }); lstResults.Add(new SearchResult() { Title = "Abc Company", ID = 3 }); lstResults.Add(new SearchResult() { Title = "Access Company", ID = 4 }); lstResults.Add(new SearchResult() { Title = "Anvil Company", ID = 5 }); lstResults.Add(new SearchResult() { Title = "Atlas Company", ID = 6 }); IEnumerable search = null; IEnumerable Data = null; if (dm.Where != null && dm.Where.Count > 0) //Filtering { search = from n in lstResults where n.Title.StartsWith(dm.Where[0].value.ToString().ToUpper()) select n; // Filtering } if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting { Data = operation.PerformSorting(search, dm.Sorted); // do sorting with the filtered result } return Json(Data); // return the sorted result } } Sorting data in server side in datamanager Filtering data in server side in datamanager Output: |
| |
| View: @(Html.EJ().Grid<object>("Edittemplate") .Datasource(ds => ds.URL("/Grid/UrlDataSource").UpdateURL("/Grid/UrlUpdate").InsertURL("/Grid/UrlInsert").RemoveURL("/Grid/UrlDelete") .Adaptor(AdaptorType.UrlAdaptor)) . . . . . .Columns(col => { col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); col.Field("CustomerID").HeaderText("Customer ID").Width(200).EditTemplate(a => { a.Create("create").Read("read").Write("write"); }).TextAlign(TextAlign.Right).Width(90).ValidationRules(v => v.AddRule("required", true)).Add(); . . . . . })) </div> <script type="text/javascript"> function create() { return $("<input>"); } function write(args) { var dataManager = ej.DataManager({ url: "/Grid/UrlDataSource", adaptor: "UrlAdaptor" }); args.element.ejAutocomplete({ width: "100%", dataSource: dataManager,fields: { text:"CustomerID"} ,enableDistinct: true, value: args.rowdata !== undefined ? args.rowdata["CustomerID"] : "" }); } . . . . . . </script> Controller public ActionResult UrlDataSource(DataManager dm) { IEnumerable DataSource = OrderRepository.GetAllRecords(); DataOperations ds = new DataOperations(); List<string> str = new List<string>(); if (dm.Search != null && dm.Search.Count > 0) { DataSource = ds.PerformSearching(DataSource, dm.Search); } if (dm.Where != null && dm.Where.Count > 0) //Filtering { DataSource = ds.PerformWhereFilter(DataSource, dm.Where, dm.Where[0].Operator); } if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting { DataSource = ds.PerformSorting(DataSource, dm.Sorted); if(dm.Where[0].Operator == "startswith") // return the sorted value of Autocomplete from here return Json(DataSource); } var count = DataSource.Cast<EditableOrder>().Count(); DataSource = ds.PerformSkip(DataSource, dm.Skip); DataSource = ds.PerformTake(DataSource, dm.Take); return Json(new { result = DataSource, count = count }); } |
|
<ej-grid id="FlatGrid" allow-paging="true">
<e-datamanager url="/Home/DataSource" adaptor="UrlAdaptor" />
<e-toolbar-settings show-toolbar="true" toolbar-items='@new List<string> {"add","edit","update","cancel","delete"}' />
<e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true" edit-mode="@(EditMode.Batch)"></e-edit-settings>
<e-columns>
<e-column field="EmployeeID" header-text="FirstName" width="80" foreign-key-field="EmployeeID" foreign-key-value="FirstName" datasource="@ViewBag.datasource">
<e-edit-template create="create" read="read" write="write"></e-edit-template>
</e-column>
</e-columns>
</ej-grid>
<script id="template" type="text/javascript">
function create()
{
return $("<input>");
}
function write(args)
{
var dataManger = ej.DataManager({ url: "/Home/Data", adaptor: new ej.UrlAdaptor() });
// Query creation
var Query = ej.Query().select("EmplyeeID", "FirstName");
var val = ej.isNullOrUndefined(args.rowdata["EmployeeID"]) ? "" : args.rowdata["EmployeeID"];
args.element.ejAutocomplete({
dataSource: dataManger,
query: Query,
showPopupButton: true,
enableAutoFill: true,
fields: { text: "FirstName", key: "EmployeeID" },
width: "100%"
});
}
function read(args)
{
var data = args.ejAutocomplete("getSelectedItems")[0];
if (!data)
return {};
return data["EmployeeID"];//normal and other edit modes
}
</script> |