We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SelectItems not whorking

Thread ID:

Created:

Updated:

Platform:

Replies:

147854 Sep 25,2019 07:12 PM UTC Sep 30,2019 07:20 AM UTC Angular - EJ 2 5
loading
Tags: ListBox
LUCIANO ALMEIDA PIMENTA
Asked On September 25, 2019 07:12 PM UTC

I have a ListBox and need to select items according to a list. I tried to use the code:

@ViewChild ('listBoxDetails')
public ddlList: ListBoxComponent;
...
public setfield = {
     groupBy: "type",
     text: "description",
     value: "code"
}
...
this.ddlList.selectItems ([description], true);

I already used in the parameter the value and the text and none worked.

Vinoth Kumar Sundara Moorthy [Syncfusion]
Replied On September 26, 2019 08:39 AM UTC

Hi Luciano, 
 
Thank you for contacting Syncfusion support. 
 
We have checked your requirement “To select Item in Listbox using selectItems method” and we have prepared a sample to achieve it using created event in ListBox as like in the below code example, 
 
HTML 
<ejs-listbox #listBoxDetails [dataSource]='data' [fields]='ddlFields' (created)="onCreated()"></ejs-listbox> 
 
TS 
import { Component, ViewEncapsulation, ViewChild } from '@angular/core'; 
import { ListBoxComponent, FieldSettingsModel } from '@syncfusion/ej2-angular-dropdowns'; 
 
export class AppComponent { 
    @ViewChild('listBoxDetails', {static: true}) 
    public ddlList: ListBoxComponent ; 
    // dataSource definition 
    public data: { [key: string]: Object }[] = [ 
        { text: 'Cabbage', type: 'Leafy and Salad', code: 'item1' }, 
        //.. 
    ]; 
    public ddlFields: FieldSettingsModel = { groupBy: 'type', text: 'text', value: 'code' }; 
    onCreated(){ 
        this.ddlList.selectItems(['Spinach']); 
    } 
     
} 
 
 
Could you please check the above sample and get back to us if you need any further assistance on this? 
 
Regards, 
Vinoth Kumar S

LUCIANO ALMEIDA PIMENTA
Replied On September 26, 2019 10:58 AM UTC

Good Morning
I adapted the example to my need, but it still didn't work.

I don't know if it makes a difference, but I'm using CheckBox:
public selectionSettings: SelectionSettingsModel = {showCheckbox: true};

When I adapted this code in your example, it didn't work.

Also, the data that fills the control is not fixed, it comes from a query (list filled in ngOnInit)

Vinoth Kumar Sundara Moorthy [Syncfusion]
Replied On September 27, 2019 11:54 AM UTC

Hi Luciano, 
 
Good day to you. 
 
We have checked your reported issue in ListBox with selectionSettings and it is properly working in our end. Please refer the below code snippet, 
 
app.component.html 
<ejs-listbox #listBoxDetails [dataSource]='data' [selectionSettings]='selectionSettings' [fields]='ddlFields' (created)="onCreated()"></ejs-listbox> 
 
app.component.ts 
import { ListBoxComponent, FieldSettingsModel, SelectionSettingsModel } from '@syncfusion/ej2-angular-dropdowns'; 
 
//.. 
public selectionSettings: SelectionSettingsModel = {showCheckbox: true}; 
 
app.module.ts 
import { ListBoxAllModule, DropDownListModule, CheckBoxSelectionService } from '@syncfusion/ej2-angular-dropdowns'; 
 
//.. 
@NgModule({ declarations: [ AppComponent ], imports: [ ListBoxAllModule, DropDownListModule, BrowserModule], providers: [CheckBoxSelectionService], bootstrap: [AppComponent] 
}) 
export class AppModule { } 
 
 
Could you please check the above sample and get back to us if you need any further assistance on this? 
 
Regards, 
Vinoth Kumar S

LUCIANO ALMEIDA PIMENTA
Replied On September 27, 2019 01:06 PM UTC

Good Morning

It worked, but I had to declare my list in code. If I use a query, it doesn't work.

I believe the Created event runs before the query populates the control.

But no problem, I'll use it anyway.

Thanks.

Vinoth Kumar Sundara Moorthy [Syncfusion]
Replied On September 30, 2019 07:20 AM UTC

Hi Luciano, 
 
You are most welcome. Please feel free to contact us if you need any further assistance on Syncfusion components. 
 
Regards, 
Vinoth Kumar S 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon