What is the process for setting data in a subgrid within an expandable grid?

Here is the structure of my array:

$scope.ebObjArr = [{key: 'val', monthsArray: [{myDate:'',}]},{myDate:'',}]

The monthsArray is responsible for populating the sub-grid. I am struggling to figure out how to populate data in the sub-grid.

This is what I have tried:

 for (let i = 0; i < $scope.ebObjArr.length; i++) {
    $scope.ebObjArr.monthsArray[i].subGridOptions = {
        columnDefs: [{ name: "Month", field: "myDate" }, { name: "Cost", field: "totalCost" }, {name:"Units consumed", field : "unitsConsumed"}],
        data: $scope.ebObjArr[i].monthsArray
    }
}

I also attempted this approach:

for (let i = 0; i < $scope.ebObjArr.length; i++) {

                for (let j = 0; j < $scope.ebObjArr[i].monthsArray[j].length; j++) {
                    $scope.ebObjArr[i].monthsArray[j].subGridOptions = {
                        columnDefs: [{ name: "Month", field: "myDate" }, { name: "Cost", field: "totalCost" }, { name: "Units consumed", field: "unitsConsumed" }],
                        data: $scope.ebObjArr[i].monthsArray[j]
                    }
                }


            }

In this example, I'm only using the MainCtrl: .

Answer №1

Although I believe there may be a more efficient solution, since no one provided an answer, I implemented this workaround which proved successful.


        onRegisterApi: function (gridApi) {
            $scope.grid1Api = gridApi;
            $scope.grid1Api.expandable.on.rowExpandedStateChanged($scope, function (row) {
                if (row.isExpanded) {
                    console.log(row.entity);
                    row.entity.subGridOptions = {
                        columnDefs: [{ name: "Month", field: "myDate" }, { name: "Cost", field: "totalCost" }, { name: "Units consumed", field: "unitsConsumed" }],
                    }
                    row.entity.subGridOptions.data = (function () {
                        var a;

                         a = $scope.ebObjArr.filter(function (val) {
                            if (val.ebName === row.entity.ebName && val.ebAddress === row.entity.ebAddress) {
                               // console.log(val.monthsArray);
                                return val.monthsArray
                            }
                            return false;
                         });
                         console.log(a);
                    console.log(a[0].monthsArray);
                    return a[0].monthsArray;
                })();
                    console.log(row.entity.subGridOptions.data);
                }

            });
        }

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

Perform a search utilizing a filter while disregarding any punctuation marks

I created a search filter for my ionic project, but I noticed that it doesn't ignore punctuations. This means that if I search for an item with a comma and forget to include the comma in my search query, I won't be able to find it. Is there a way ...

The efficient method of storing application activity logs using one schema and minimal details in MongoDB within a Node.js environment

Looking for a way to efficiently log application actions in a Node.js project with MongoDB database. We aim to include limited information such as success, action name, user id, time, etc. Any suggestions or best practices for achieving this in Node.js w ...

What is the best way to show an image on the screen once a submit button is clicked?

I have a hidden loader-bar gif that I want to display when the user submits a form. Here is the code: <p class="loadingImg" style="display:none;"><img src="/design/styles/_shared/classic-loader.gif" alt="" /></p> Is there a way to ...

Expanding an existing JSON "Key" by including additional values

To clarify, I am working with a JSON object and I would like to have the ability to manipulate it similar to how you can modify a PHP array. In PHP, you can continuously add values to an array under a specific key. For example, in PHP: $array = array(); ...

Utilizing OrbitControls with Socket.io in a Three.js Sphere

I'm currently troubleshooting an issue with my project. I have a three.js sphere ("HTML1" on Desktop) with controls (THREE.OrbitControls) that is functioning properly on both my computer and tablet. My goal is to control this sphere through my iPad, s ...

Inserting dates into a SQL platform

I am currently facing an issue where the date is being inserted into the SQL database as 30/12/1899. I am using Access 2003 for the database and cannot determine why this unexpected behavior is occurring! window.status='Loading contingency scripts - ...

Examining the execution of a function/method when a click event occurs within a functional component

It took me a while to realize that testing functional components with vue-test-utils can present some challenges In my case, I am utilizing Bootstrap-Vue's B-Button with a @click event that calls a function/method. When I attempt to test whether the ...

What is the best way to use JQuery to delete an element from a form by targeting its ID?

I am attempting to dynamically add and remove input fields within a form using JavaScript and jQuery. The concept involves having four buttons at the bottom of the form. Two buttons are dedicated to adding or deleting extra input fields for percentages "A ...

Unique hover tags such as those provided by Thinglink

Looking for a way to replicate the functionality of Thinglink? Imagine a dot on an image that, when hovered over, displays a text box - that's what I'm trying to achieve. I thought about using tooltips in Bootstrap, but I'm not sure if it ...

Guide to transmitting a variable using the JavaScript formData API

Having trouble getting AJAX file (picture) upload functionality to work because of issues with sending variables via the formData API: Here is the code for formData: var data = new FormData(); data.append('SelectedFile', _file.files[0]); data.a ...

Incorporating a personalized event into a directive

I've developed a unique custom directive that generates a field within a larger form. To simplify, here's a snippet of the code: .directive('entityField', function () { return { restrict: 'E', scope: { ...

How can you determine the status of an individual checkbox within a reactjs (material-table) component?

In my project, I have implemented a table that displays a list of students retrieved from a database. Upon clicking on each student row, a modal popup appears showing another table with 4 rows and 3 columns. Each column in the modal contains 4 checkboxes. ...

What is the most efficient way to update a specific element in a redux/vuex store?

What is the most efficient way to update an element(hash) in a list within a store (redux, vuex) using O(1) complexity? The order of the elements must be maintained as I will be adding/removing elements frequently. Updates will occur every millisecond, re ...

The update function in my Vuejs3 project is not functioning as expected when trying to use JSON data to populate the

Recently, I started working with vuejs 3 and json. My goal is to update a course, however, despite my efforts, the fields for the course (title and content) remain empty with no errors being displayed. In views/blog/OnePost, I am passing the ID of the cour ...

A guide on integrating a submission button that combines values from multiple dropdown forms and redirects to a specific URL

Is there a way to make the submit button on this form act based on the combined values of two different dropdown menus? For instance, if "west" is selected from the first dropdown and "winter" is selected from the second dropdown, I want it to navigate to ...

The mesmerizing world of Vue templates and transition groups

My previous simple list had transitions working perfectly, but now that I am using components and templates the transitions no longer work. Can anyone help me understand why? I want each item to animate individually, but it seems like all items are transi ...

Cease the process of filtering the array when the condition is not fulfilled at the upcoming index, even if there are still remaining elements that could meet the criteria at that

I am curious about extracting data from filtered results where the filter process automatically halts if the conditions are not met in the following index during filtering. Below is an example of the code I created: let array = [1, 2, 3, 4, 5, 100, 12, 13, ...

Wait for the successful $save in AngularJS before redirecting

How can I redirect to my list page after POSTing a form if there are no errors and the data is successfully saved in the database? app.controller('NoteCreateController', ['$scope', 'Note', '$routeParams', '$l ...

Troubleshooting: Missing JQuery Header in Table

I'm currently working on creating a table using JQuery and everything seems to be functioning properly, except for one issue - the header is not displaying. I have defined the header, appended it to the table, and then added the column names to the he ...

Troubleshooting the malfunctioning of an AngularJS basic form

Today marks the beginning of my journey with learning AngularJS. I've spent the last half an hour trying to figure out why the scope isn't being called correctly. Could it be a problem with CodePen? My previous attempt worked flawlessly. Any help ...