0

I get next data structure array from api:

 var data = [
                    {
                        id: 1,
                        name: 'test 1',
                        properties: [
                            {
                                id: 101, 
                                name: 'custom 01'
                            },
                            {
                                id: 102,
                                name: 'custom 02'
                            }
                        ]
                    },
                   {
                       id: 2,
                       name: 'test 2',
                       properties: [
                           {
                               id: 201,
                               name: 'custom 21'
                           },
                           {
                               id: 202,
                               name: 'custom 22'
                           }
                       ]
                   }
                   and etc ...
                ]

I need to display data from nested array properties from each record. This is how I'm trying to do:

    $scope.gridOptions = {};
    $scope.gridOptions.columnDefs = [];
    $scope.gridOptions.data = data.data;


    $scope.load = function (param) {

            lovServices.events(param)
                .then(function (response) {

                    var events = response.events;

                    for (var i = 0; i < events.length; i++) {
                        console.log(events[i].eventProperties)
                        $scope.gridOptions.data = events[i].eventProperties
                    }

                })
        }
    });

console.log(events[i].eventProperties) shows me the right data set, but the grid is still empty. I appreciate if somebody could tell me where is my mistake? Thanks in advance.

4
  • any plunker or fiddle, can you post your html? Commented Dec 20, 2016 at 22:08
  • @YaserAdelMehraban plnkr.co/edit/dgIkqq2eFnRUAGHvmkzJ?p=preview it displays data but only for one record Commented Dec 20, 2016 at 22:12
  • After checking your plunker and adding a ; after console.log and data = events[i].eventProperties, it seems it is working. Check here: plnkr.co/edit/jyqiT5e1k4Uo8ZPUQjCz?p=preview Commented Dec 20, 2016 at 22:24
  • @YaserAdelMehraban it works wrong, it might be 9 columns and 4 rows, instead 7 columns and 9 rows Commented Dec 20, 2016 at 22:27

1 Answer 1

0

In order to build your grid, you need to take a look at $scope.gridOptions.columnDefs = [];

Check http://ui-grid.info/docs/#/tutorial/201_editable up, there is the example of how to define each column with the help of columnDefs property using your array of objects

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

1 Comment

I'm trying to set it dynamic, that's why I didn't define columns

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.