rowsRendered produces Cannot read property 'apply' of undefined

321 views
Skip to first unread message

mportugal

unread,
Aug 14, 2016, 9:23:19 PM8/14/16
to UI-Grid Support

Hi,

I'm using version v3.1.1 of ui-grid. I'm trying to use on.rowsRendered and I get the error in the subject.
Here's my code, with a lot of column defs snipped out:

var myTestApp = angular.module('Test', ["ui.router", "ui.grid", "ui.grid.pagination"]);
myTestApp.controller('myTestController', function($scope, $http, uiGridConstants){
  $scopemyTestGrid = {
    columnDefs: [
      {
        displayName: "Client's Name",
        field: 'client_last_name',
        cellTemplate: 'partials/app/myapp/clients/client_first_last.php',
        width: "30%",
        enableFiltering: true,
      },
    ],
    rowHeight: 40,
    enableFiltering: true,
    enableColumnMenus: false,
    paginationPageSizes: [25, 50, 75],
    paginationPageSize: 25,
    onRegisterApi: function(gridApi) {
      $scope.gridApi = gridApi;
      $scope.gridApi.core.on.rowsRendered($scope, test('asdf'));
    }
  };

In another file that is included and does run:

function test(msg){ alert(msg); }
The error occurs after the alert. The alert occurs before the rows are actually displayed.
Full error:

TypeError: Cannot read property 'apply' of undefined
 at https://my.server.com/myapp/bower_components/angular-ui-grid/ui-grid.min.js:7:30735
 at m.$emit (https://my.server.com/myapp/bower_components/angular/angular.min.js:147:47)
 at Object.f.raise.(anonymous function) [as rowsRendered] (https://my.server.com/myapp/bower_components/angular-ui-grid/ui-grid.min.js:7:31771)
 at p.setVisibleRows (https://my.server.com/myapp/bower_components/angular-ui-grid/ui-grid.min.js:7:18921)
 at https://my.server.com/myapp/bower_components/angular-ui-grid/ui-grid.min.js:7:17028
 at https://my.server.com/myapp/bower_components/angular/angular.min.js:130:409
 at m.$eval (https://my.server.com/myapp/bower_components/angular/angular.min.js:145:107)
 at m.$digest (https://my.server.com/myapp/bower_components/angular/angular.min.js:142:173)
 at m.$apply (https://my.server.com/myapp/bower_components/angular/angular.min.js:145:401)
 at l (https://my.server.com/myapp/bower_components/angular/angular.min.js:97:250)(anonymous function)

My goal is to have the function eventually set the height of the grid's containing element depending on the number of rows displayed. So maybe there's a better way to do that? It would have to be as simple, because using the function works even with the console errors.

Is it a bug or a feature and I don't have the syntax right? Commenting out the rowsRendered line makes the error go away.

Thanks!

- @rramsey

mportugal

unread,
Aug 14, 2016, 9:57:07 PM8/14/16
to UI-Grid Support
Hi rramsey this appears to be a syntax issue. When you pass a handler into any listener on UI-Grid, you are simply supposed to pass the function name, but in your example you passed a function call instead. So to resolve your problem, simply remove the ('asdf') from your function and leave only the function name as in the plunker bellow:
Reply all
Reply to author
Forward
0 new messages