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

1 Answer 1

0

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

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

2 Comments

TypeError: Cannot read property 'data' of undefined, Obviously, call is always async...
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 stackoverflow.com/questions/15299850/…

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.