import { Component, ViewChild, AfterViewInit, ViewEncapsulation } from '@angular/core';
import { EJAngular2Module, ListViewComponent } from 'ej-angular2';
@Component({
selector: 'ej-app',
templateUrl: './app.component.html',
styleUrls: ['app.style.css'],
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
@ViewChild('listInstance')
public listInstance: ListViewComponent;
listdata: object[];
fieldsdata: object;
constructor() {
this.listdata =
[{ "Texts": "Discover Music" },
{ "Texts": "Sales and Events" },
{ "Texts": "Categories" },
{ "Texts": "MP3 Albums" },
{ "Texts": "More in Music" }];
this.fieldsdata = { "text": "Texts" };
}
clicked() {
this.listInstance.widget.setModel({ 'selectedItemIndex': -1 });
}
} |
<ej-listview #listInstance [dataSource]="listdata" [fieldSettings]="fieldsdata" width=100 persistSelection=true></ej-listview>
<br>
<input type="button" value="Un Select" (click)='clicked($event)'> |
Hi Kishore,
Thanks for the update.
In our previous sample, we have provided for EJ1 ListView. For EJ2 ListView, We can deselect an item in listview by removing the "e-active" class from the selected item.
We can utilize “getselectedItems” method for getting selected items from the listview and remove the ‘e-active’ class from that item.
Please refer the below link for sample
https://stackblitz.com/edit/typescript-ck5y3e?file=index.html
Please check it and let us know if you have any concerns.
Thanks,Christo
On the more modern version I did this on the event being sent assuming I clicked the item got a dialog and now want to deselect on the same event
event.item.classList.remove('e-active');
let list: any = new ListView({
dataSource: flatData,
});
list.appendTo('#app');
let btn1 = new Button({ cssClass: `e-primary` });
btn1.appendTo('#btn2');
btn1.element.onclick = (): void => {
if (list.getSelectedItems()!=undefined&& (list.getSelectedItems().item as HTMLElement).classList.contains('e-active')) {
(list.getSelectedItems().item as HTMLElement).classList.remove('e-active');
}}; |