I have a angular uiGrid on my page. The only time it will display data is if i set data in gridOptions and not on http success call back. Here is the code:
$scope.gridOptions = {
showfooter: false,
enablePaging: true,
paginationPageSizes: [15],
paginationPageSize: 50,
enableRowSelection: false,
primaryKey: 'Id',
multiSelect: false,
enableSorting: false,
enableVerticalScrollbar: true,
enableHorizontalScrollbar: true,
groupable: false,
rowHeight: 75,
columnDefs:
[
{
field: 'Id', visible:false
},
{
field: 'Name'
},
{
field: 'CategoryName',
DisplayName: 'Category'
},
{
field: 'Actions',
DisplayName: 'Actions',
cellTemplate: '<a href="#" title="Edit" ng-click="goToEditInst(row)"><span class="glyphicon glyphicon-edit"></span></a>'
}
]
};
$scope.searchInstituions = function () {
var formObj = $scope.searchForm;
var svc = formObj.service;
var city = formObj.city;
var cat = formObj.category;
var params = { CategoryId: ((cat == null)?-1:cat.Id) , ServiceId: ((svc == null) ? -1 : svc.Id), Cityid: ((city == null) ? -1 : city.Id) };
$http({
method: 'POST',
url: '/getjson',
data: $.param(params),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
})
.success(function (data, status, headers, config) {
data = [{ "Id": 1, "Name": "Golden Hills School District No. 75", "CategoryName": "Schools" }];
$scope.gridOptions.data = data;
})
.error(function (data, status, headers, config) {
alert('Error: ' + status + ". " + data);
});
};
Note that I have hardcoded data as array of one element.
The html for this is:
<fieldset ng-controller="InstitutionController">
<legend>Search Results:</legend>
<div class="gridStyle" ui-grid="gridOptions"></div>
</fieldset>
The grid does not display any rows when $scope.gridOptions.data is set on .success callback. (It is being called for those who are going to ask if the function is called
But is I set it in grid options like following it displays just fine:
$scope.gridOptions = {
data: [{ "Id": 1, "Name": "Golden Hills School District No. 75", "CategoryName": "Schools" }],
showfooter: false,
enablePaging: true,
paginationPageSizes: [15],
paginationPageSize: 50,
enableRowSelection: false,
primaryKey: 'Id',
multiSelect: false,
enableSorting: false,
enableVerticalScrollbar: true,
enableHorizontalScrollbar: true,
groupable: false,
rowHeight: 75,
columnDefs:
[
{
field: 'Id', visible:false
},
{
field: 'Name'
},
{
field: 'CategoryName',
DisplayName: 'Category'
},
{
field: 'Actions',
DisplayName: 'Actions',
cellTemplate: '<a href="#" title="Edit" ng-click="goToEditInst(row)"><span class="glyphicon glyphicon-edit"></span></a>'
}
]
};
What am I missing here!!!