czeckd / angular-dual-listbox

Angular 14 component for a dual listbox control.
https://czeckd.github.io/angular-dual-listbox/
MIT License
83 stars 73 forks source link

How to get selected elements? #6

Closed rahulserver closed 8 years ago

rahulserver commented 8 years ago

I tried this plugin. The only issue which I see is that when we move the items from source to destination list, the confirmed array(in demo-app.component.ts) is always empty.

Here is my revised demo-app.component.ts to test this:

import { Component } from '@angular/core';

import { DualListComponent } from './dual-list.component';

@Component({
    selector: 'demo-app',
    template: `
<div class="container-fluid">
    <button (click)="testBtn()">Test</button>
    <p></p>
    <dual-list [sort]="keepSorted" [source]="stations" [(destination)]="confirmed" height="265px"></dual-list>
</div>
`
})

export class DemoAppComponent {

    private keepSorted:boolean = true;

    private stations:Array<any> = [ 
        { _id: 1, _name: 'Antonito' },
        { _id: 2, _name: 'Big Horn' },
        { _id: 3, _name: 'Sublette' },
        { _id: 4, _name: 'Toltec' },
        { _id: 5, _name: 'Osier' },
        { _id: 6, _name: 'Chama' },
        { _id: 7, _name: 'Monero' },
        { _id: 8, _name: 'Lumberton' },
        { _id: 9, _name: 'Duice' },
        { _id: 10, _name: 'Navajo' },
        { _id: 11, _name: 'Juanita' },
        { _id: 12, _name: 'Pagosa Jct' },
        { _id: 13, _name: 'Carracha' },
        { _id: 14, _name: 'Arboles' },
        { _id: 15, _name: 'Allison' },
        { _id: 16, _name: 'Tiffany' },
        { _id: 17, _name: 'La Boca' },
        { _id: 18, _name: 'Ignacio' },
        { _id: 19, _name: 'Oxford' },
        { _id: 20, _name: 'Florida' },
        { _id: 21, _name: 'Bocea' },
        { _id: 22, _name: 'Carbon Jct' },
        { _id: 23, _name: 'Durango' },
        { _id: 24, _name: 'Home Ranch' },
        { _id: 25, _name: 'Trimble' },
        { _id: 26, _name: 'Hermosa' },
        { _id: 27, _name: 'Rockwood' },
        { _id: 28, _name: 'Tacoma' },
        { _id: 29, _name: 'Needleton' },
        { _id: 30, _name: 'Elk Park' },
        { _id: 31, _name: 'Silverton' },
        { _id: 32, _name: 'Eureka' }
     ];

    private confirmed:Array<any> = [];

    testBtn(){
        console.log("This.confirmed: " + JSON.stringify(this.confirmed));
    }
}

So am I doing it wrong somewhere? Or what is the way to get the selected elements in confirmed array?

rahulserver commented 8 years ago

OK I found out that simply dragging an item and dropping to the other list does not update the confirmed array. We need to press the add button. I think this is confusing. If simply dragging the item from source to destination array does not update the confirmed list then it should not be allowed or the confirmed list should contain the items.

czeckd commented 8 years ago

Thanks! There was an issue with drag-and-drop and not updating the confirmed array.

I have made a change to the demo and dual-list.component.ts to trueUp after a drag-and-drop.

rahulserver commented 8 years ago

@czeckd thanks for the extremely quick fix! Really the change works as expected.

I also issued a new pull request for another issue. Kindly review that.

I am enjoying your plugin so thank you very much! :)

Suhas-Nadarge commented 5 years ago

after selecting each options, How can we pass individual value? Can you exxplain please