I was looking at the Ui Grid tutorials and saw them using a filter to populate drop downs within each row of the grid.
I am trying to understand the concept and see if I may use this to get the options using a $http.get
method or using a service.
Can someone point me to a better tutorial or guide me?
I wrote something like
$scope.ContractDetails.columnDefs = [
{ name: 'Contract_Detail_Id', enableCellEdit: false, visible: false },
{ name: 'Contract_Id', enableCellEdit: false, visible: false },
{ name: 'Contract_Detail_Sl', displayName: 'Sl', enableCellEdit: false },
{ name: 'Contract_Cust_Location', displayName: 'Customer Location' },
{
name: 'Contract_Cust_Location', displayName: 'Customer Location',
editableCellTemplate: 'ui-grid/dropdownEditor',
editDropdownIdLabel: 'Loc_Id', editDropdownValueLabel: 'Loc_Name',
editDropdownOptionsArray: $scope.clientLocs,
cellFilter: 'mapClientLocs:row.grid.appScope.clientLocs:"Loc_Id":"Loc_Name"'
},
{
name: 'Fixed_or_Percentage', displayName: 'Fixed %', editableCellTemplate: 'ui-grid/dropdownEditor',
cellFilter: 'mapFixed', editDropdownValueLabel: 'Fixed_or_Percentage', editDropdownOptionsArray: [
{ id: false, Fixed_or_Percentage: 'Fixed' },
{ id: true, Fixed_or_Percentage: 'Percentage' }
]
},
]
And added the two filters:
.filter('mapFixed', function () {
var fixedHash = {
false: 'Fixed',
true: 'Percentage'
};
return function (input) {
if (!input) {
return '';
} else {
return fixedHash[input];
}
};
})
.filter('mapClientLocs', function (ClientDataService) {
var clientLocs = {};
ClientDataService.GetClientLocs()
.then(function (response) {
clientLocs = response;
console.log("response", response);
return clientLocs;
});
return clientLocs;
});
The first filter is working fine. But the one where I am trying to get the data from the service, that is not working. I get an error like angular.js:11655 TypeError: fn.apply is not a function