Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

selectpicker ui-jq is not populating records #2670


User avatar
0
bilalhaidar created

Hi, I am looking at similar Razor views in the solution to see how to populate a select with live search. Below is the code. The problem is the select control is never populated, instead it shows "Nothing Selected".

I made sure data is returned from server. I can see them on the Chrome Developer Tool.

Thanks

View:

<select class="form-control bs-select" name="Shelter" id="Shelter" ng-model="vm.poc.shelter"
                        ui-jq="selectpicker"
                        data-live-search="true">
                    <option ng-repeat="shelter in vm.shelters"
                            value="{{shelter.id}}">{{shelter.label}}
                    </option>
                </select>
                <label>@L("Shelter")</label>

Controller:

vm.shelters = [];
vm.init = function () {
                vm.loading = true;
                commonLookupService.getReferenceTables().then(function (result) {
                    vm.shelters = result.data.shelters;
                }).finally(function () {
                    vm.loading = false;
                });
            }

            vm.init();

5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think you need to refresh selectpicker after getting data from server. There are examples in the project, you can check them.

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    That is correct if I am using ng-options to bind elements, but in my case I am just looping over items.

    Check App/common/views/languages/texts.cshtml

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I couldn't be sure at the moment. Have you tried refreshing anyway ? It is simple to try.

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    Maybe I was mistaken, a refresh is needed and it works now.

    Although in the texts.cshtnl, the languages array is set to static values in the controller and it shows without problems, however, the source names because they are loaded from db, a refresh was used.

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks, great :)