Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui-grid 3.0 and editDropdownOptionsArray with $http #2050

Closed
xavadu opened this issue Nov 10, 2014 · 8 comments
Closed

ui-grid 3.0 and editDropdownOptionsArray with $http #2050

xavadu opened this issue Nov 10, 2014 · 8 comments

Comments

@xavadu
Copy link
Contributor

xavadu commented Nov 10, 2014

Hello,

It isn't possible to assign editDropdownOptionsArray to a columDefs loading it async with $http?

PoC:

CountryModel.get().then(function(r){
    $scope.countries = r.data.data;
});

$scope.gridOptions = {
    columnDefs: [
         {field:'country_iso', displayName:'Country ISO',
                editableCellTemplate: 'ui-grid/dropdownEditor', 
                editDropdownOptionsArray: $scope.countries,
                editDropdownIdLabel: 'country_iso',  
                editDropdownValueLabel: 'country_name'
        },
    ]
}

or any solution to accomplish it?
Thanks

@PaulL1
Copy link
Contributor

PaulL1 commented Nov 10, 2014

It is, but not via an interim variable. This is a pointer thing - you're making editDropdownOptionsArray a pointer to $scope.countries when $scope.countries is empty - so it's a pointer to an empty array. Then later you replace the $scope.countries pointer with a pointer to a new array, but the editDropDownOptionsArray isn't updated. If you instead did:

CountryModel.get().then(function(r){
    $scope.gridOptions.columnDefs[0].editDropdownOptionsArray = r.data.data;
});

it would probably work.

@xavadu
Copy link
Contributor Author

xavadu commented Nov 12, 2014

It worked!

Thanks!

@xavadu xavadu closed this as completed Nov 12, 2014
@crediblebytes
Copy link

Shouldn't the correct functionality of editDropdownOptionsArray be expected to be a pointer? Order of the columns can change.

@PaulL1
Copy link
Contributor

PaulL1 commented Mar 24, 2015

It should be expected to be a pointer. But the problem in this example was outside ui-grid:

var A = [1, 2, 3];
var B = A;
A = [3, 4, 5];

Irrespective of ui-grid, B is still pointing to [1, 2, 3]. In the example above @xavadu never set the dropdown options into a variable that ui-grid could see, equivalent to giving ui-grid B and expecting us to somehow now that A has changed.

@jainrocks
Copy link

@PaulL1 It worked! But is there any other way of not using " $scope.gridOptions.columnDefs[0]" since the colDefs may change regularly.

@tseanf
Copy link

tseanf commented Jun 15, 2016

I have this working, instead of assigning a new array instance, just loop through your data returned and .push it into the existing array and all will be well.

        if (promise.data) {
            promise.data.forEach((item) => list.push(item));
        }

@alexey-vasyunin
Copy link

@tseanf Could you show demo with your solution, please? At plnkr or real site.

@lacivert
Copy link

lacivert commented Feb 16, 2017

@alexey-vasyunin I think this would be for the same example;

CountryModel.get().then(function(r){
    // $scope.gridOptions.columnDefs[0].editDropdownOptionsArray = r.data.data; //not this but same as
    r.data.data.forEach((item) => $scope.countries.push(item));
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants