1

I have a problem a problem with showing data in ui grid table.

I have defined an API from which I want to show data and I can access them through the browser, but the problem is in showing rendered data. Here is my angular controller in which I've defined function for getting data from API:

        getData();

        $scope.myData = [];

        $scope.gridOptions.data = []

        $scope.gridOptions.data = $scope.myData; 

        function getData() {
            $http.get('/load/').success(function (data) {
                data.forEach( function( row, index ) {
                    $scope.myData.push(data);
                });
                $scope.gridOptions.data = data;
                console.log('data from api', data);
            })
        };

and I got empty grid. enter image description here

Data are showed in console: enter image description here

I've also tried to parse data var jsonObj = JSON.parse(data);, but I got an error Unexpected token o at Object.parse (native)

4 Answers 4

1

Use this function to push your data into an array. Check your data in the console, drill down into your data. (click on the arrow) My data is within the .doc yours may be within another attribute. change the "items[i].doc" to the correct attribute for your data.

// pass data.rows to function items params
// the type is to filter 
function fncArray(items,type) {
    var filtered = [];
    for(var i=0; i < items.length; i++)  {
        if ( items[i].doc.type = type){
            filtered.push(items[i].doc);
        }
    }
    // console.log(filtered);
   return filtered;
}

this is to use without filtering

// pass data.rows to function items params 
function fncArray(items) {
    var newData= [];
    for(var i=0; i < items.length; i++)  {
            newData.push(items[i].doc);
    }
   return newData;
}
Sign up to request clarification or add additional context in comments.

Comments

0

you can write $scope.$apply() to trigger changes in controller

2 Comments

I got an Error: [$rootScope:inprog] $digest already in progress
you can check it if phase is running if(!$scope.$$phase) { $scope.$apply()}
0

Returned data should be ["key":[object, object, object, object]] in this form. 1) convert this data using var jsonObj = JSON.parse(data); 2) Use this expression in success !$scope.$$phase?$scope.$apply():null;

1 Comment

I've tried this and again the same error appears: Unexpected token o at Object.parse (native)
0

I'm sorry guys, my mistake here. There is no need for parsing. I've defined wrong columnDefs here in controller :facepalm:

Comments

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.