Search code examples
angularjsrubyui-grid

AngularJS ui-grid rendering issues with multiple grids on a page


I have a pages that is currently running 4 grids. The main grid that is loaded with the page is users, and then 3 more grids are loaded in a Modal each in it's own tab. The issue that i have been having is that when i added the 4th, 3rd on in the modal, the other two or the last one will not render. I get the grid outline but no data. This is happening randomly each time i load the modal.

my gridOptions looks like this:

` $scope.gridOptionsAdd = {
    enableColumnResizing: true,
    enableSorting: true,
    data: $scope.newAdd,
    columnDefs: [
      {name: 'Address Type', field: 'addressTypeDescription'},
      {name: 'Data', field: 'addressData'},
      {name: 'Primary', field: 'primaryYn'},
      {name: 'Private', field: 'privateYn'},
      {name: 'Remove', cellTemplate: ' ' +
        '<button type="button" class="usrView btn btn-danger btn-sm" ng-click="grid.appScope.groupRemove(row.entity.id)">' +
        '<div class="fa fa-trash" data-toggle="tooltip" data-pacement="bottom" title="View User"></div>' +
        '</button>'
      }
    ],
    onRegisterApi: (gridApi) ->
      $scope.gridApiAdd = gridApi
      $interval( () ->
        $scope.gridApi.core.handleWindowResize()
      , 500, 10)
  }`

Each of the 3 grid are the same code except for the 3rd variable in $interval; they are 10, 18 and 26. The modal code is this:

` #open edit user modal
  $scope.userEdit = (id) ->
    $scope.userId = id
    $modalInstance = $uibModal.open ({
      animation: $scope.animationsEnabled,
      templateUrl: 'userEditModal.html',
      controller: 'editUserInCtrl',
      keyboard: true,
      size: 'lg',
      scope: $scope,
      resolve: {
        data: () ->
          return  EntryUsr.get({id: id }).$promise
        ,
        address: () ->
          return EntryAdd.query({user_id: id}).$promise
        ,
        addType: () ->
          return EntryAddType.query().$promise
        ,
        usrPosition: () ->
          return EntryPos.query().$promise
      }
    })
    $scope.updateGrpTable()
    $scope.updateRoleTable()
    $scope.updateAddTable()`

The last 3 calls pull the user's group, security settings and address and write them to the grids; $scope.gridOptionsAdd.data = data .

The grids are defined in the HTML as:

 %div.grid#grid3{'ui-grid'=>'gridOptionsRole'}

Each grid has its's own ID and refers to a different gridOption set

I get nothing in my console except for 3 errors compling that it can read property 'core'

angular.self-a3680ff….js?body=1:13643 TypeError: Cannot read property 'core' of undefined
    at user.self-2a6c9f3….js?body=1:200
    at callback (angular.self-a3680ff….js?body=1:12457)
    at Scope.$eval (angular.self-a3680ff….js?body=1:17379)
    at Scope.$digest (angular.self-a3680ff….js?body=1:17192)
    at Scope.$apply (angular.self-a3680ff….js?body=1:17487)
    at tick (angular.self-a3680ff….js?body=1:12447)

Many thanks.


Solution

  • The issue I was having is related to this ticket, 5151. Because the grids where in a modal there was in issue with Angulars show function to resolve this issue the gridOptions calls where changed to this:

    $scope.gridOptionsAdd = {
        enableColumnResizing: true,
        enableSorting: true,
        data: $scope.newAdd,
        columnDefs: [
          {name: 'Address Type', field: 'addressTypeDescription'},
          {name: 'Data', field: 'addressData'},
          {name: 'Primary', field: 'primaryYn'},
          {name: 'Private', field: 'privateYn'},
          {name: 'Remove', cellTemplate: ' ' +
            '<button type="button" class="usrView btn btn-danger btn-sm" ng-click="grid.appScope.groupRemove(row.entity.id)">' +
            '<div class="fa fa-trash" data-toggle="tooltip" data-pacement="bottom" title="View User"></div>' +
            '</button>'
          }
        ]
      }
    

    in my application.js file, ui.grid.autoResize was added:

    angular.module('myApp', [
                                "ngResource",
                                "ui.bootstrap",
                                "ui.grid",
                                "ngFileUpload",
                                "ui.grid.autoResize"
                            ]);
    

    HAML templates I added the ui-grid-auto-resize tag

    %div.grid#grid4{'ui-grid'=>'gridOptionsAdd', 'ui-grid-auto-resize'=>''}