smj
smj

Reputation: 11

ui.grid data displayed is the same on each row

I am using a cell template for each row in my data grid. If I qualify the json object with an index then the value appears correctly but of course it is the same for each row. If I remove the index, then all rows are displayed with the same value but the value is an array.

---the js file (function() { angular.module('xxxSurvey').controller('EditxxxSurveyController', EditxxxSurveyController); EditxxxSurveyController.$inject = ['$scope', 'UserFacilityListService', 'xxxSurveyService']; function EditxxxSurveyController($scope, UserFacilityListService, xxxSurveyService) { $scope.dataLoaded = false; $scope.currentPage = 1; $scope.pageSize = 10;

    // test ui-grid setup

    $scope.dataLoaded = true;

    $scope.editWorksheetOptions = {
        enableSorting: true,
        columnDefs: [
            {
                name: 'all', field: 'MasterPatientId', width: 40,
                enableSorting: false, enableColumnMenu: false, pinnedLeft: true,
                //cellTemplate: '<input type="checkbox" id="i{{COL_FIELD}}">'
                cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.worksheetInfo.MasterProviderId}}</div>'
            },


            {name: 'residentName', field: 'residentName', minWidth: 90, pinnedLeft: true,
                cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.editWorksheetOptions.data[0].ResidentNameLast}}</div>'
            },
            {name: 'residentRoom', field: 'residentRoom', width: 90, pinnedLeft: true},
            {name: 'status', field: 'status', width: 90},
        ],
        data: []
    };

    $scope.$on('FacilitySelected', function() {
        if (UserFacilityListService.getSelectedFacility()) {
            $scope.selectedFacility = UserFacilityListService.getSelectedFacility();
        }
        var promise = xxxSurveyService.getCurrentWorksheet($scope.selectedFacility.MasterProviderId);
        promise.then(
            function(payload) {
                if (payload !== null) {
                    $scope.worksheetInfo = payload.worksheetInfo;
                    $scope.editWorksheetOptions.data = payload.residentData;


                }
            }
        );
    });

}

})();

--the json data

[{"AssessmentId":1,"WorksheetId":4,"MasterPatientId":1,"ResidentNameFirst":"xx","ResidentNameMiddle":"^","ResidentNameLast":"zzz","ResidentNameSuffix":"^"}, {"AssessmentId":2,"WorksheetId":2,"MasterPatientId":2,"ResidentNameFirst":null,"ResidentNameMiddle":null,"ResidentNameLast":null,"ResidentNameSuffix":null}]

--the html div id="editWorksheetGrid" ui-grid="editWorksheetOptions" class="grid" ui-grid-pinning>

Upvotes: 0

Views: 831

Answers (1)

Mayur Patel
Mayur Patel

Reputation: 1

i had same issue. For me it was rowIdentity problem. Define following in your controller.

$scope.gridOptions.rowIdentity = function (row) {
    return row.ID;  //make sure ID is unique.
};

This fixed my problem. Thanks

Upvotes: 0

Related Questions