Using ag-Grid to bind data from an external service file

Just getting started with angular and exploring ag-grid. I have a service in one file and a controller in another, where I am able to see the grid column headers but struggling to bind the data from my service to the grid. Can someone please point out what I might be missing?

I attempted to use:

gridOptions.datasource = myDataSource; -- as shown on the ag-grid site, but couldn't get it to work.

rmdsServices.js

(function () {
'use strict';
var rmdsServices = angular.module('rmdsServices', ['ngResource']);

rmdsServices.factory('rmds', ['$resource',
  function ($resource) {
      return $resource('/api/rmd/', {}, {
          query: { method: 'GET', params: {}, isArray: true }
      });
  }]);

})();

rmdsController.js

(function () {
angular
.module('rmdsApp', ['agGrid', 'rmdsServices'])
.controller('rmdsController', rmdsController)


rmdsController.$inject = ['$scope', 'rmds'];
function rmdsController($scope, rmds) {
    $scope._rmd = rmds.query();


    var columnDefs = [
        { headerName: "RMDID", field: "RMDID", width: 150, editable: true },
        //other columns defs

    ];


    var rowData = $scope._rmd;


    $scope.gridOptions = {
        columnDefs: columnDefs,
        enableFilter: true,
        angularCompileFilters: true,
        enableSorting: true,
        rowSelection: 'single',
        enableColResize: true,
        rowData : rowData,
        angularCompileRows: true
    };
};

})();

After adding the following code, I can see the objects returning back but they are still not binding to the grid. When I put in an alert, I can see the objects coming back but it doesn't bind to the grid. Apologies for any confusion, I'm quite new to angular.

Update:


        var rowdata = $scope._rmd;
    rmds.query().$promise.then(function (res) {
        $scope._rmd = res;            
    });

    $scope.gridOptions = {
        columnDefs: columnDefs,
        //enableFilter: true,
        //angularCompileFilters: true,
        //enableSorting: true,
        //rowSelection: 'single',
        //enableColResize: true,
        rowData: $scope._rmd
       // angularCompileRows: true
    };

Answer №1

It's important to ensure that you are assigning the correct value to your grid data. Make sure to set $scope._rmd with the response from your service call success.

Here is an example of how to do it:

rmds.query().$promise.then(function (res){
    $scope._rmd = res;
});

// Update the table once $scope._rmd has a value
$scope.gridOptions = {
    columnDefs: columnDefs,
    enableFilter: true,
    angularCompileFilters: true,
    enableSorting: true,
    rowSelection: 'single',
    enableColResize: true,
    rowData: $scope._rmd,
    angularCompileRows: true
};

Answer №2

Make sure to use gridOptions.api.setRowData() to refresh the data once the grid has finished initialization.

rmds.query().$promise.then(function (response){
    $scope.gridOptions.api.setRowData(response);
});

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

AngularJS form submission is acting up

I have been working on a tutorial about routing and controllers, but I am facing an issue. There are no errors in my code, but the form is not sending the variables to the controller! I have tried different methods to submit the form, including using a bu ...

What is the significance of the space between form.validate and .ng-invalid-email.ng-dirty?

I'm currently working on an AngularJS application and I'm confused about the spacing between "form.validate" and ".ng-invalid-email.ng-dirty" in the stylesheet code below: <style> form.validate .ng-invalid-required.ng-dirty {background ...

Issue with the default zoom setting on Google Maps

Encountering an issue with Google Map default zoom. Despite changing the zoom value, it is not responding as expected. Any assistance on this matter would be greatly appreciated. Thank you in advance for your help. <script src="http://maps.google.com ...

tips for converting a stdclass object into an array using php and javascript

To begin, I utilize a jQuery plugin called tableToJson to extract the table values as a JSON object. Next, I convert the JSON object using JSON.stringify which results in the following output: Array ( [0] => stdClass Object ( [Kode] => 4 ...

tips for extracting data from a json array

Hello everyone, I have a question that I could use some help with. I have a set of data that looks like this: var data = { "values":[[1,2,3],[2,4,3],[3,6,7],[1,4],[6,4,3,4],[6,7,3,5]] } Currently, I am trying to create a multiple line chart usi ...

Group Hover by StyleX

I recently experimented with the innovative StyleX library and encountered a particular challenge. Can a group hover effect be achieved for a component solely using this library? For instance, let's assume we have the following component in Tailwind ...

Encountered a CPU-side conversion issue causes Browser to crash when attempting to load an object using threejs

After implementing the code from the threejs example/loader/obj/mtl to load an object exported via Unity3d, some customers have reported browser crashes on their machines. A screenshot of the error message in a browser console can be viewed here. Addition ...

Switch out the Angular panel with a simple click event

I have developed an angular application using bootstrap. You can view the app on this plunker link <div class="panel col-lg-3 col-md-3 col-sm-2"> <div class="" id="menu"> <div ng-controller="mylistcontroller" cl ...

Creating a file structure for JavaScript files in a Vue CLI project

When structuring my Vue CLI project, I'm struggling to find clear documentation on best practices. Currently, I have 10 modules each with an associated JS file. My approach so far involves organizing all the pages in my router.js within a views direc ...

Prevent spaces from being entered in a textbox in asp.net with JavaScript

How can I prevent spaces from being entered into a textbox using JavaScript? My current script works, but fails when the space bar is pressed continuously. Any suggestions on improving this issue would be greatly appreciated. Below is the code I am curren ...

Is NodeJS to blame for the background image not working?

HTML and CSS Issue <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" href="/css/style.css"> </head> <body> & ...

Error message: `$injector:modulerr - Angular JS` - Indicates an

Currently, I am trying to delve into the world of Angular JS by taking the codeschool course "Shaping up with angular js". The instructor in the videos emphasizes the importance of wrapping code in function(){}. However, upon attempting to do so, an error ...

Tips on returning the array

I've been struggling to figure out how to extract the 'sheetsArray' from the code snippet below so that I can use it for various tasks. Despite my efforts and hours of searching online, I haven't been able to find a solution. It seems l ...

How to send emails with attachments using WordPress?

Looking for assistance in sending emails with attachments using Wordpress. I am struggling and believe there might be something missing in my code. Any help would be greatly appreciated! :) Below is the code spread across two files: Name (required)<b ...

Naming a JSON object twice

As a newcomer to node.js, I find myself struggling with understanding the process. Can someone please guide me on where I might be going wrong? This is how I create a new Product exports.postAddProduct = (req, res, next) => { const product = new Produ ...

Keeping an object in a multidimensional array based on its ID in Angular 4/Ionic 3 without removing it

Exploring a complex data structure: [{ propertyoutsideid: 1, items: [ {itemId: 1, something: 'something'}. {itemId: 2, something: 'something'}. {itemId: 3, something: 'something'}. ] },{ prope ...

Guidance on Applying Texture to a Targeted Area of a 3D Model in Three.js

Currently immersed in a Three.js project, I find myself faced with the challenge of projecting a texture onto a particular surface of a 3D model. Despite loading the model through GLTFLoader and possessing the necessary texture, my attempts at using Raycas ...

Errors found during compilation when running the npm start command

After choosing to develop an app with React using VS Code, I initiated the process by running npm create-react-app ./, which was a success. However, when I proceeded to execute the command npm start, it resulted in compilation errors related to files suc ...

Exploring the Overlapping of Objects in Three.js

I am dealing with multiple meshes in my code and I am trying to figure out how to make the renderer display the object that should be in front, somewhat similar to what is shown in this example: --> . I have read about render depth, but I am unsure of h ...

Angular's focus function poses certain challenges that need to be addressed

I am seeking assistance as a new programmer facing a beginner's challenge. I have two inputs and I would like to enter a series of numbers in the first input (DO) and have them automatically populate in the second input (communal code). Inputs: http ...