0

I am trying to create a ui-grid with some DDL filter (from get data). If I try with async: false, all works perfectly. This is the call:

var Documents = [];

var solutionSetColumn = {};
var solutionSetFilters = [];

LoadData = function () {
        Documents = [];
        $.ajax({
            type: "POST", url: url,
                success: function (data) {
                Documents = data.d;
            },
            error: function (err) {
            }
        });
    }
}

$.ajax({
    type: "POST", url: url,
    success: function (data) {
        solutionSetColumn = { field: 'SolutionSet', displayName: 'Solution Set', width: 190, filter: { type: uiGridConstants.filter.SELECT, selectOptions: data.d } };
    },
    error: function (err) {
        solutionSetColumn = { field: 'SolutionSet', displayName: 'Solution Set', width: 190 }
    }
});       

LoadData();

gridOptions = {
    enableHorizontalScrollbar: 2, 
    enableVerticalScrollbar: 0,
    enableFiltering: true,
    data: Documents,
    columnDefs: [
        { field: 'Name', displayName: 'Nome File', width: 200 },
        solutionSetColumn
    ]
}

$scope.gridOptions = gridOptions;
});

How to get all async without gridOption error like colDef undefined? Obviously without the setTimeout! Thanks

vinS
  • 1,417
  • 5
  • 24
  • 37
Michele Boscagin
  • 97
  • 1
  • 1
  • 10

1 Answers1

0

You need to move your $scope.gridOptions (and the options definition) into the success path of your ajax call.

ESP32
  • 8,089
  • 2
  • 40
  • 61
  • `TypeError: Cannot read property 'data' of undefined`, Obviously, call is always async... – Michele Boscagin Feb 10 '17 at 15:32
  • The problem is, that you have multiple asyn calls. You can either put each one into its parent (as I suggested), or use promises. See http://stackoverflow.com/questions/15299850/angularjs-wait-for-multiple-resource-queries-to-complete – ESP32 Feb 10 '17 at 15:38