Trying to create simple working app with ng-grid and ASP.NET MVC. Client side:
var app = angular.module('TestApp', ['ngGrid'])
app.controller('MainController', function ($scope, $http) {
$scope.addresses = []
$scope.filterOptions = {
filterText: "",
useExternalFilter: true
};
$scope.update = function () {
$http.get('/Home/GetData', {
params: { filter: $scope.filterOptions.filterText }
})
.then(function (result) {
$scope.addresses = result.data
//alert(JSON.stringify(result))
})
$scope.$apply()
}
$scope.update()
$scope.gridOptions = {
data: 'addresses',
headerRowHeight: '50',
columnDefs: [
{ field: 'country', headerCellTemplate: '<table><tr><td>Country</td></tr><tr><td ng-controller="MainController"><input type="text" placeholder="" ng-model="filterOptions.filterText"/></td></tr></table>' },
{ field: 'city'},
{ field: 'street'},
{ field: 'house'},
{ field: 'zipcode'},
{ field: 'datec'}
]
};
$scope.$watch('filterOptions', function (newVal, oldVal) {
if (newVal !== oldVal) {
$scope.update()
}
}, true);
I can see that i get correct data from:
public ActionResult GetData(string filter)
{
var query = from c in db.Addresses where c.country.Contains(filter) select c;
return Json(query.ToList(), JsonRequestBehavior.AllowGet);
}
In my code, the .then callback is called, and I can browse all the returned adin data.addresses. Yet, nothing is displayed in the grid. No error appears in the console.