@Html.EJ().Autocomplete("search").Datasource((IEnumerable<object>)ViewBag.autoData).MinCharacter(3)
<script type="text/javascript"> $(function (e) { $('#search').keyup(function (e) { if (e.keyCode == 13) { $(this).trigger("enterKey");//trigger function on enter } }); $('#search').bind("enterKey", function (e) { var searchVal = e.target.value; //condition to check if the typed characters is of minlength 3 if (searchVal.length >= 3) { $("#Grid1").ejGrid("search", searchVal);//sends a search request to Grid1 $("#Grid2").ejGrid("search", searchVal);//sends a search request to Grid2 } else if (searchVal.length == 0) { $("#Grid1").ejGrid("clearSearching");//clear searching on Grid $("#Grid2").ejGrid("clearSearching"); } }); })
|
$('#search').bind("enterKey", function (e) { var searchVal = e.target.value; //condition to check if the typed characters is of minlength 3 if (searchVal.length >= 3) { var obj = $("#Grid1").ejGrid("instance");//create grid instance for (var key in obj.model.currentViewData[0])//traverse through the first JSON array of the dataSource obj.model.searchSettings.fields.push(key);//push the field names to the searchSettings.fields array $("#Grid1").ejGrid("search", searchVal);//sends a search request to Grid1 $("#Grid2").ejGrid("search", searchVal);//sends a search request to Grid2 }
|
<div style="margin-top:30px"> @(Html.EJ().Grid<object>("Grid") .Datasource(d => d.URL("/Home/DataSource").Adaptor(AdaptorType.UrlAdaptor)) .AllowScrolling() .ScrollSettings(scroll=>scroll.Width("100%").Height(300).AllowVirtualScrolling())//Virtual Scrolling enabled . . . . .ClientSideEvents(eve=>eve.ActionBegin("OnBegin")) ) </div>
<script type="text/javascript">
//actionBegin event of the Grid function OnBegin(args) { if (args.requestType == "searching") { for (var key in args.model.currentViewData[0])//traverse through the first JSON array of the dataSource args.model.searchSettings.fields.push(key);//push the field names to the searchSettings.fields array } } public ActionResult DataSource(DataManager dm) { IEnumerable DataSource = OrderRepository.GetAllRecords(); DataOperations operation = new DataOperations(); DataResult result = new DataResult();
result.result = DataSource; if (dm.Search != null)//if search query is not null { result.result = operation.PerformSearching(result.result, dm.Search);//for search operations } result.count = result.result.AsQueryable().Count(); if (dm.Skip > 0) result.result = operation.PerformSkip(result.result, dm.Skip);//for skip action
if (dm.Take > 0) result.result = operation.PerformTake(result.result, dm.Take);//for take action
return Json(result, JsonRequestBehavior.AllowGet); } |