3

I am new to Angularjs , I want to display the JSON data from webservice response to in grid form by using ng-grid .My code is here

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;
      });

But In the above code the PostData is not defined.my ng-grid scope is 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 how can i get the data from json object to myData ? so that i can use ng-grid as

<div ng-controller="TestController">

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

here the my personal url (it is confidential so i don't want to show ) The above code shows sometimes as postData is not defined and sometimes getting 405 error .

Please explain the problem with the plunker link

2
  • How does myData look like? Commented Apr 21, 2014 at 7:29
  • actually i am in doubt how to generate grid ,in case of myData the grid fields are shown above ,and in the $http syntax unfortunately i used $scope.persons instead of myData which was bind in the controller . Commented Apr 22, 2014 at 9:21

1 Answer 1

3

The 'data' property in ng-grid accepts the name of the data object, in your case the name is "persons" since the response from your HTTP request goes to $scope.persons.

Example:

 $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'}
]
 };

Live example: http://plnkr.co/edit/UndbtO?p=preview

Sign up to request clarification or add additional context in comments.

1 Comment

It is best suited for me ,thank you Alex Choroshin ,your plunker explain the my problem solution .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.