What happens when 'grid' property is undefined in modal?

I encountered an issue with my modal where I wanted to display pre-selected rows, but kept getting a 'cannot read 'grid' of undefined' error. The UI Grids are defined within the modal, and I have declared two Grid APIs with different names. Below is the code snippet:

This function launches the modal:

    //edit user group
    $scope.editSelectedGroup = function(){
        //get the selected row
        var row = $scope.gridApiInfo.selection.getSelectedRows();

        var modalInstance = $modal.open({
            animation: true,
            templateUrl: 'userGroupModal.html',
            controller: 'UserGroupModalController',
            resolve: {
                modalTitle: function () {
                    return "Edit User Group"
                },
                allDepartments: function () {
                    return $scope.allDepartments;
                },
                allRegions: function() {
                    return $scope.allRegions;
                },
                isEdit: function(){
                    return true;
                },
                row: function(){
                    return row[0];
                }
            }
        });

This is the content of the modal controller:

    .controller('UserGroupModalController',function($scope,$modalInstance,$modal,$window,modalTitle,allDepartments,allRegions,isEdit,row,referenceDataService){

    // Controller logic here

    });

Upon clicking the button to launch the modal, no modal appears - instead, a console error stating 'Cannot read property 'grid' of undefined' is thrown at the line involving $scope.deptGridApi.grid.rows.map. Any suggestions on how to resolve this issue? Thank you in advance!

After further testing, I found that fetching selected rows using deptGridApi and gridApiRegions works fine. As evidenced by the test function triggered by clicking a button in the modal:

        $scope.getDeptandRegions= function(form){
            $log.log($scope.gridApiRegions.selection.getSelectedRows());
            $log.log($scope.deptGridApi.selection.getSelectedRows())  
         };

Even though these operations also utilize the grid APIs, they log the selected rows correctly. Could it be that they are only activated after pressing a button?

Answer №1

When $scope.deptGridApi.grid.rows.map is causing an error saying 'Cannot read property 'grid' of undefined', it means that:

$scope.deptGridApi === undefined

This issue is likely occurring because the onRegisterApi function is either:
- Never called
- Called with "undefined" as a parameter

If you can provide a working code snippet, I may be able to offer more specific guidance.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Validation message causing Bootstrap form inline to lose center alignment

Could someone please assist me with form inline in Bootstrap? I am trying to ensure that all inputs are of the same height (or centered), but I'm facing an issue when a validation message is displayed. DEMO: http://codepen.io/Tursky/pen/gpvgBL?editor ...

Is it possible to retrieve the createdAt timestamp without displaying the 'GMT+0000 (Coordinated Universal Time)'?

After conducting an extensive search, I have yet to find a satisfactory answer. My goal is to configure it without including the CUT time. {name: "Registered:", value: `${user.createdAt}`}, {name: "Joined:", value: `${message.guild.joinedAt}`} Presently, ...

Is there a way to transform time into a percentage with the help of the moment

I am looking to convert a specific time range into a percentage, but I'm unsure if moment.js is capable of handling this task. For example: let start = 08:00:00 // until let end = 09:00:00 In theory, this equates to 100%, however, my frontend data ...

The download functionality in HTML5 is not functioning properly, so users are forced to rename files when downloading

For weeks, I've been struggling to change the name of the downloaded file. Despite my efforts, instead of being named Chrysanthemum.jpg, it ends up as a hash of the file like 241693260.jpg In my backend setup, I utilize Node.js and Express.js for man ...

Loading screen featuring an outlined blueprint of design elements

Can anyone identify the technology or language used to create the preloader screen on websites like the one shown in this link? The elements have a sweeping shine effect while loading. This style of preloader screen can be seen on popular websites such as ...

Iterate over an array utilizing the $.getJSON method for data retrieval

I have encountered an issue while using a for loop to iterate through an array of dates in a JSON request. The problem is that the loop seems to be fetching only the first item in the array each time it iterates, as if ignoring the variable i or being cach ...

Encountering difficulty when trying to establish onclick functionality on dynamically loaded table through

Currently, I am working on a website where I am building a timeline using AJAX. I encountered an issue while trying to set the onclick event on each table row. I initially used a class selector but it did not produce any effect. After reading a post on St ...

Utilizing sorting and filtering functionalities on an Angular data table

Recently, I decided to enhance my Angular skills by downloading a demo app. While working on the basics of Angular, I encountered a problem with applying a filter and sort to a data table in the app. Despite referring to some examples, I am uncertain about ...

Tips for updating the default value of an HTML <select> tag using a customized <select> option

I'm struggling to update the value of my <select><option value=""></option></select> based on a custom select option I created. Customizing select options using JS and jQuery is necessary since they can't be easi ...

What Is Preventing my Bootstrap Tabs from Displaying their Content?

I've been attempting to implement the nav-tabs feature from Bootstrap (version 5.2.2) into my Angular application. However, I've encountered an issue where only the content in the first tab is visible, while the contents of the other tabs remain ...

Double array summation function

It is necessary for me to calculate the total coursePrice from this JSON data source here using AngularJS (javascript). I need to calculate two sums: one for each school and another for all schools combined. I have already displayed all the data in a tabl ...

Obtain ng-model data upon sending a POST request to an Express.js endpoint

I am currently developing a Node.js application that incorporates AngularJS. My goal is to execute a simple POST request using Angular. This POST request should send a set of values to my server, where I can view them using the console.log function. With ...

How can a CSS class be used to toggle the visibility of a DIV element with JavaScript?

I've been researching and came across several scripts that allow for toggling the contents of a DIV by clicking on a button, however, they all use IDs. What I am looking to achieve is similar but using classes instead of IDs. This way, if I want to h ...

What is the best way to make the Nav bar overlap instead of shifting content to the right?

Is there a way to open the nav bar and have it overlap on the right without pushing content to the right? I tried experimenting with position and z-index, but it didn't work. Thank you! Link <div id="mySidebar" class="sidebar" ...

Transform an HTML table string into JSON format

I discovered a useful library called table to JSON that allows me to convert an HTML Table to JSON using its ID (#testtable in the example below): var table = $('#testtable').tableToJSON(); alert(JSON.stringify(table)); However, I am interested ...

I am encountering an issue where propData in Vue Jest is returning as undefined

I have encountered an issue while passing the propData in my jest test file for a Vue component. It seems that the propData is not being set to the component and instead, I am receiving an error saying "cannot read property of clouds of undefined." Could i ...

Identify and troubleshoot scripts that are included in the response returned by Chrome

I am facing an issue where I have a webpage that loads HTML sections through an AJAX call. The response includes both HTML and JavaScript files. Currently, I am trying to figure out how to set a debug point on the JavaScript file. In Internet Explorer, I ...

How to create a sequence of queries to a mongoDB database (using mongoose) depending on a condition

Source Code let placeForSearch="hampi" let filteredHotelFacilities=req.body.filter //["Free Wifi"] let hotels = await Hotel.find({placeForSearch}) .where("facilities") .select(selectedProperties) .skip(pageNu ...

Separate a string using commas but disregard any commas inside quotation marks

Similar Question: JavaScript code for parsing CSV data There is a string that looks like this: "display, Name" <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3d49584e497d49584e49135e5250">[email protected]</a> ...

``What is the mechanism behind callbacks in AngularJS when making a call to a REST service?

Currently, I am diving into the world of AngularJS and REST. The code snippet that I'm analyzing has the term callback repeatedly used in an authentication function. I'm curious to know if "callback" is a JavaScript or Angular keyword, or simply ...