Search code examples
angularjsangular-ui-gridui-grid

Passing Object Property in UI-Grid Getting Undefined Error


Having issues with passing in Object Property in UI Grid.

I'm attempting to pass a object property to a function by using the cellTemplete option in UI-Grid but I'm getting an undefined error.

I was able to pass the index to the function, just not the actual property of the row data.

How can I get the object property through to the deleteMember function?

vm.TeamMembersGridOptions = {
    enableGridMenu: false,
    enableSorting: true,
    enableHorizontalScrollbar: 0, /*always hide horizontal scroll bar*/
    enableVerticalScrollbar: 1, /*always show vertical scroll bar*/
    rowHeight: 40,
    minRowsToShow: 5,
    columnDefs: [
        {
            enableHiding: false,
            enableColumnMenu: false,
            width: '10%',
            field: 'edit',
            cellClass: 'ui-grid-cell-contents',
            cellTemplate:
                '<a class="ui-action-type-mouse" ng-click="grid.appScope.vm.deleteMember(rowRenderIndex, row.entity.member)" title="Delete"><img src="resources/images/fa_remove.png"></img></a>'
        },
        data: vm.teamMembers
    ]

function deleteMember(idx, member) {
    console.log(member);
    var params = {
        member: vm.teamMembers[idx]
    };
    var user = params.member.userProfile;
    var current = params.member.current;
    var messageText;
    var headerText;
    if (!current) {
        messageText = "Are you sure you want to delete this user: " + user.firstName + " " + user.lastName + "(" + user.email + ")?";
        headerText = "Delete Team Member?";
    }
    else {
        messageText = "Are you sure you want to delete yourself from this team? You will no longer be able to access this project if you continue.";
        headerText = "Delete Yourself?";
    }
}  
<div ng-if="!vm.loadingTeam" ui-grid="vm.TeamMembersGridOptions" ui-grid-auto-resize></div>

Solution

  • You're passing in vm.teamMembers to the grid. So each item in the vm.teamMembers array is row.entity in the cellTemplate.

    Try just passing in row.entity instead of row.entity.members.