Binding grid in angular on user-driven events.
Thanks for using Syncfusion Products.
We analyzed your query and we created a sample in Web API using Custom Service data in Angular Grid . While using custom service data we have initialize an empty data in the controller. For server side searching, we achieved using by sending dynamic url to the controller.
We performed searching operation using OdataQueryOptions. ODataQueryOptions parameter in server side controller which contains all the required parameters for performing server side operations such as paging, sorting, searching and filtering
In OnComplete method, we have maintained the current state of the searching in Grid because of the dataSource changes will be cleared the grid current state. Once the angular $apply cycle is completed we have stored the current state of searching operation to the Grid.
Please refer the following code snippet :
|
<div ng-app="employeeView"> <div ng-controller="GridCtrl"> OrderID : <input type="text" ng-model="logQuery.OrderID" class="textbox" /> <button ej-button e-field-size="large" e-field-showroundedcorner="true" ng-click="Search()">Search</button> <div ej-grid id="Grid" e-width="500px" e-datasource="data" e-allowsorting="true" e-allowPaging="true" e-toolbarsettings-showtoolbar="true" e-toolbarsettings-toolbaritems="tools"> <div e-columns> <div e-column e-field="OrderID" e-headertext="Order ID" e-isprimarykey="true" e-textalign="right"></div> <div e-column e-field="CustomerID" e-headertext="Customer ID" e-textalign="right"></div> <div e-column e-field="EmployeeID" e-headertext="Employee ID" e-textalign="right"></div> <div e-column e-field="Freight" e-headertext="Freight" e-textalign="right"></div> </div> </div> </div> </div>
<script> angular.module('custModule', []).factory("custService", ["$http", function ($http) {
return { get: function () { return $http.get("/api/Orders/?", { cache: true }); }, search: function (value) {
return $http.get("/api/Orders/?$inlinecount=allpages&$filter=(substringof(" + "'" + value + "'" + " ,tolower(OrderID))) or (substringof(" + "'" + value + "'" + ",tolower(CustomerID))) or (substringof(" + "'" + value + "'" + ",tolower(Freight))) or (substringof(" + "'" + value + "'" + ",tolower(ShipCountry)))") } }; }]);
angular.module('employeeView', ['ejangular','custModule']) .controller('GridCtrl', function ($scope, custService) {
$scope.tools = ["add", "edit", "delete", "update", "cancel"];
$scope.Search = function () { var grid = $("#Grid").ejGrid("instance"); var scope = angular.element($("#Grid")).scope(); custService.search(scope.logQuery.OrderID).then(onComplete); }
$scope.data = []; custService.get().then(
function (response) {
$scope.data = response.data.Items; } )
function onComplete(response) { $scope.data = response.data.Items; } }); </script> public PageResult<OrdersView> Get(ODataQueryOptions opts) { var results = db.OrdersViews.AsQueryable(); var count = results.Count(); if (opts.OrderBy != null) results = opts.OrderBy.ApplyTo(results); if (opts.Filter != null) { if (opts.Filter.RawValue.Contains("substring")) { 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)); } else results = opts.Filter.ApplyTo(results, new ODataQuerySettings()).Cast<OrdersView>(); } if (opts.InlineCount != null) count = results.Count(); var data = results; //var count = emp.Count; //if (opts.Filter != null) // count = data.Cast<OrdersView>().ToList().Count;
return new PageResult<OrdersView>(results, null, count); |
For your convenience we have created a sample and same can be downloaded from the below link
Sample Link : http://www.syncfusion.com/downloads/support/forum/119401/ze/ServerOperations1317383374
If we misunderstood your query, please get back to us, we will be happy to assist you.
Please let me know if you need any further assistance.
Regards,
Prasanna Kumar N.S.V
- 1 Reply
- 2 Participants
-
MH Mario Hines
- Jun 16, 2015 06:42 PM UTC
- Jun 17, 2015 12:50 PM UTC