Reputation: 11
Why is the Group-Row empty, when i push the Edit Button? I want to have the same value there from the list, when the Edit Mode is on an the Dropdown is visible.
How can i resolve this?
Please check this Working Code:
Here is my plnkr
var app = angular.module("employment", ["xeditable"]);
app.run(function(editableOptions) {
editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
});
app.controller('EditableRowCtrl', function($scope, $filter, $http)
{
$scope.users = [];
$http.get('userdata.json').success(function(data){
$scope.users = data;
});
$scope.statuses = [
{value: 1, text: 'aktiv'},
{value: 2, text: 'inaktiv'}
];
$scope.groups = [
{id: 1, text: 'Administrator'},
{id: 2, text: 'SuperUSer'},
{id: 3, text: 'Mitglied'},
];
$scope.showGroup = function(user) {
if(user.group && $scope.groups.length) {
var selected = $filter('filter')($scope.groups, {id: user.group});
return selected.length ? selected[0].text : 'Not set';
} else {
return user.groupName || 'Not set';
}
};
$scope.showStatus = function(user) {
var selected = [];
if(user.status) {
selected = $filter('filter')($scope.statuses, {value: user.status});
}
return selected.length ? selected[0].text : 'Not set';
};
// remove user
$scope.removeUser = function(index) {
$scope.users.splice(index, 1);
};
// add user
$scope.addUser = function() {
$scope.inserted = {
id: $scope.users.length+1,
name: '',
status: null,
group: null
};
$scope.users.push($scope.inserted);
};
});
Upvotes: 1
Views: 613
Reputation: 1350
@M1ke, I don't know if you're still working on this. I just saw this question. The problem is that your status and group codes are defined as strings in userdata.json and integers in the statuses and groups objects. I just changed them to integers in the userdata and it worked like a charm.
Upvotes: 1