Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
15
Wont Pre-populate the selected igx-combo-box
posted

Hi,

Igx-combo won't prepopulate values coming from backend unless we put setTimeOut. Is there any other way around it? 

Without setTimeOut it will have the option pre-selected but won't show it in the box but upon expanding the list, it is there and selected too but not in the box itself.

HTML:

<div class="d-flex">
                    <div class="w-100">
                      <igx-combo
                        appComboItemWithTooltip
                        appOpenOnFocus
                        #eventNoCombo
                        [itemsMaxHeight]="250"
                        [data]="eventInfoList"
                        [displayKey]="'eventNumber'"
                        [valueKey]="'eventNumberId'"
                        formControlName="eventNumber"
                        (selectionChanging)="handleEventNumberselection($event)"
                        searchPlaceholder="Enter a {{
                          numberLabel | lowercase
                        }} number to search"
                      >
                      </igx-combo>
                    </div>
                  </div>

TS:

populateEventNumber(eventNo: string): void {
    
    if (eventNo) {
      const eventNumber: string[] = [];
      eventNumber.push(eventNo);
      setTimeout(() => {
        this.upsertEventForm.controls.eventNumber.patchValue(eventNumber);
      }, 350);
    }
  }


because of which this happens:



it loads after a while.

pacakge-json:

 "@igniteui/material-icons-extended": "^2.10.0",
    "@infragistics/igniteui-angular": "^12.2.3",
Please advice.
Parents Reply
  • 700
    Offline posted in reply to Sayantan Basu

    Hello Sayantan,

    Thank you for following up!

    I have been looking into your clarifications and what I could say, as demonstrated in out Two-Way Binding section here, is that setting a predefined selection could be achieved via the ngModel and passing an array of items of the same type as the ones in the combobox's selection (based on valueKey).

    However, from your initial forums post, I have noticed that you are using reactive forms on your side and, with this in mind, in the previously attached sample, I have set the initial selection like the following when creating the control:

    constructor(fb: FormBuilder, ...) {
        this.registrationForm = fb.group({
        
            // Creating the control with predefined selection based on valueKey
            // the igx-combo accepts an array of items
            // so the selcted item/items should be set as an array, e.g. [1] / [1, 3,...]
            product: [[1], { nonNullable: true }],
        });
        
        // OR
        // this.registrationForm.controls['product'].setValue([1]);
        // this.registrationForm.controls['product'].setValue([1, 3,...]);
    }

    In the abovementioned example, I am setting the predefined selection like the following:

    product: [[1], { nonNullable: true }],

    as the incoming data has the following structure:

    [
        {
            "ID": 1,
            "ProductName": "Chai",
            ...
        },
        {
            "ID": 2,
            "ProductName": "Chang",
            ...
        },
        ...
    ]

    and the combo’s valueKey and displayKey properties are set like the following:

    <igx-combo
        #combo
        [data]="data"
        displayKey="ProductName"
        valueKey="ID"
        formControlName="product"
    ></igx-combo>

    From the above configuration, when the data is loaded, the first record, i.e., { ID: 1, "ProductName": "Chai" }, is marked as selected and displayed in the combo's input.

    Additionally, please note, as mentioned in our Handling Selection section here, that:

    When the combobox is bound to remote data, setting value/selected items through API will only take into account the items that are loaded in the current chunk. If you want to set an initial value, make sure those specific items are loaded before selecting.

    However, as I am not sure of the overall configuration of your application and the isolated sample seems to be working correctly and cannot reproduce the described behaviors, I cannot tell for sure what the reason for this behavior could be without having a working sample that I can debug on my side.

    Having this in mind, in order to assist you further, it would be highly appreciated if you could provide me with a small sample demonstrating the behavior on your side. Also, if possible, it would be great if you could try and modify the provided by me sample here, so it reproduces the issue.

    Alternatively, if the behavior cannot be replicated, please feel free to provide your own sample. Remove any external dependencies and code that are not directly related to the issue, zip your application, and attach it in this forum thread.

    Thank you for your cooperation. Looking forward to your reply.

    Sincerely,
    Riva Ivanova
    Associate Software Developer

Children
No Data