implementing ng-grid to showcase json information within an angularjs application

Recently I started learning Angularjs and I am looking to showcase the JSON data retrieved from a webservice response in a grid format using ng-grid. Here is my code snippet:

function TestController($scope, $http) {
alert("test");
$http({
      url: 'http://my_Personal_Url',
      method: "POST",
      data: postData,
      headers: {'Content-Type': 'application/jsonp'}
  }).success(function (data, status, headers, config) {
          $scope.persons = data; //  
      }).error(function (data, status, headers, config) {
          alert("test2");
          $scope.status = status;
      });

However, in the provided code, PostData is not defined. The scope for ng-grid looks like this:

 $scope.gridOptions = { 
data: 'myData',
columnDefs: [
{field: 'DirectLine', displayName: 'DirectLine'},
{field:'Email', displayName:'Email'}
{field:'Employee', displayName:'Employee'}
{field:'Extention', displayName:'Extention'}
{field:'Id', displayName:'Id'}
{field:'PhoneNumber', displayName:'PhoneNumber'}
{field:'Title', displayName:'Title'}
]
 };

Now my question is how can I populate myData with the JSON object data so that I can utilize ng-grid as follows:

<div ng-controller="TestController">

    <div class="gridStyle" ng-grid="gridOptions"></div>
</div>

In this case, my personal URL is confidential, hence not displayed here. The issues I'm facing include occasional PostData not defined error and sometimes encountering a 405 error.

I would appreciate it if someone could provide an explanation along with a Plunker link showcasing the problem.

Answer №1

The 'data' attribute within ng-grid is used to specify the name of the data object being utilized, for example "persons" in this case as the response from the HTTP request populates into $scope.persons.

Here's a snippet:

 $scope.gridOptions = { 
data: 'persons',
columnDefs: [
{field: 'DirectLine', displayName: 'DirectLine'},
{field:'Email', displayName:'Email'}
{field:'Employee', displayName:'Employee'}
{field:'Extention', displayName:'Extention'}
{field:'Id', displayName:'Id'}
{field:'PhoneNumber', displayName:'PhoneNumber'}
{field:'Title', displayName:'Title'}
]
 };

Check out a working demo here: http://plnkr.co/edit/UndbtO?p=preview

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

What is the process for selecting the default option in a drop-down menu?

Is there a way to set the default value in a drop-down list using material-ui? I attempted to use displayEmpty="true", but it did not work. I want the first option, A, to be pre-selected so that it is visible to the user in the UI without them having to m ...

Tips for extracting a specific field from a list of objects using $push without relying on $group functionality

I have a collection of data in my database [{ "name":"Alice", "age":30 }, { "name":"Bob", "age":35 }, { "name":"Cathy", "age":25 }, { "name":"David", "age":28 }] I'm looking to extract a list of ages like ages:[30,35,25,28] Although these ar ...

Create a dynamic calendar by integrating dates with Javascript and an HTML table

Recently, I decided to delve into web design again and embark on a challenging project for my father's baseball business. The main task at hand is creating a detailed calendar using HTML tables. After spending a considerable amount of time perfecting ...

Choose options with identical titles

If you click on the button to add more selects with the same name, I want to replace them so that you can access them in a PHP array. document.querySelector('#add').onclick = function () { var thespan = document.createElement('span&apos ...

How can I ensure that VueJS only starts loading data after the initial API call has been completed?

After retrieving data from an API, I populate a form in my component. The challenge I am facing is that the watchers are triggered immediately after populating the initial data. I want them to be triggered asynchronously. Additionally, I need to prevent th ...

Using knex.js to pipe data to an express server

I'm encountering an issue with knex.js and express. Here is the code snippet in question: userRouter.get('/:userId', function (req, res) { DB('users').where({ id: req.params.userId }).first('name').pipe(res); }); ...

Is it possible to utilize various providers in Next-Auth while still maintaining the same email address?

I am currently developing a Next.js application using NextAuth. At the moment, I have implemented login functionality with Google, credentials, and GitHub. However, I encountered an issue where if a user logs in with Google using the email "[email pro ...

I am having trouble retrieving the array value from the response sent by my server

After receiving a dictionary from my server, when I try to access the values using the following code: {"filters":{ "Facture": [ "Магма (Тычок)", "Тонкий кирпич", "Гладк ...

Error: The specified element to insert before is not a direct descendant of this parent node

As I work on converting a jquery dragable script to plain javascript, I encountered an issue at the insertBefore point. The error message that pops up is: NotFoundError: Node.insertBefore: Child to insert before is not a child of this node. This particula ...

What is the best way to designate external dependencies in WebPack that are not imported using '*'?

I need assistance with specifying office-ui-fabric-react as an external dependency in my TypeScript project using Webpack. Currently, I am importing only the modules I require in my project: import { Dialog, DialogType, DialogFooter } from 'office-u ...

Issue: Bidirectional binding functionality is not functioning properly within the user interface modal

I'm currently working on displaying data in a modal, but I'm facing issues with getting two-way binding to work properly. In my HTML code: <div class="cta-actions"> <div class="action"><a class="btn btn-lg btn-max">Send a pa ...

Tips for iterating through the properties of every object within a Knockout observableArray and dynamically generating a table

My observableArray is dynamically populated with SQL data, resulting in varying columns each time. I am trying to present the SQL results in an HTML table but facing issues with the code below. This is the desired output format... var viewModel = func ...

How to work with a JSON object in Internet Explorer 6

Looking for some quick answers that should be easy for someone with expertise to provide. I have a basic asp.net site that relies on JSON for various tasks (and JSON.stringify). Everything works fine in Firefox and the like, but in IE6 I'm getting a ...

Utilizing the 'as' prop for polymorphism in styled-components with TypeScript

Attempting to create a Typography react component. Using the variant input prop as an index in the VariantsMap object to retrieve the corresponding HTML tag name. Utilizing the styled-components 'as' polymorphic prop to display it as the select ...

Invoke a handler from one function within another function

I am unsure of the best approach for achieving this, or if it is even feasible, but I have two components: a main navigation bar (NavBar) that spans across the top of the page, and a sidebar drawer. NavBar: export default function NavBar() { const c ...

Setting up vibration for local notifications in Ionic and Cordova is a straightforward process

Is there a way to enable vibration in local notifications on my mobile device for every notification I receive? Example of Local Notification Code: $cordovaLocalNotification.schedule({ id : remId, title : name.innerHTML, text : note.value, ...

I'm receiving the error message "app.get is not a function" when using Express.js. What could be

Having trouble understanding why I am getting an error: app.get is not a function in the upload.js file with the provided code snippet. In my index.js file, I have set up everything and exported my app using module.exports = app. I have also used app.set( ...

Creating dynamic JSON endpoints using JSP with Spring MVC

When working with JSON in my webapp, I have successfully passed a variable wordId to the Spring-mvc Controller using a static URL. However, I am unsure of the best practice for dealing with dynamic or parametric URLs. Controller Section: @RequestMapping( ...

Issue with swal() not triggering in Internet Explorer 11

Looking for some assistance here, I believe I might be missing a small detail. The _layout.cshtml file includes all the necessary scripts to ensure that sweetheart works on IE: (this used to work in previous versions, but we haven't had to support I ...

Having a blast with Play, Scala, and Jerkson when suddenly encountering a frustrating `

Currently, I am experimenting with using jerkson in play framework with scala 2.10. My goal is to load data fixtures from json files using the "parse" function provided by jerkson. Unfortunately, this approach is not working as expected. I am implementing ...