Skip to content

Commit f3260cd

Browse files
committed
Update demo, compiler, and readme for with locale
1 parent a291cf2 commit f3260cd

File tree

5 files changed

+57
-36
lines changed

5 files changed

+57
-36
lines changed

README.md

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
Angular Dual-Listbox
44
=========
55

6-
The **angular-dual-listbox** is an Angular 4+ component that provides two lists controls
7-
side-by-side that allows items in one list to be moved to the other list via drag-and-drop and/or a
8-
button-based interface. The component supports multiple select options from the list, programatic
9-
setting of list sources, and layout with direction and button formatting.
6+
The **angular-dual-listbox** is an Angular 4+ component that provides two lists controls side-by-side that allows items in one list to be selected and moved^*^ to the other list via drag-and-drop and/or a button-based interface. The component supports multiple select options from the list, programatic setting of list sources, and layout with direction and button formatting.
107

118
A [working demo](http://czeckd.github.io/angular-dual-listbox/demo/) shows the dual listbox in action.
129

10+
\* Technically, the dual-list component does not move items from one array to another. Rather it makes a copy from the source array of the item and adds it to the destination array, or removes it from the destination array. Thus, the source array is a master list of all available item and the destintion array is a list of items that have been selected from the master list. Therefore, in order for an item to be in the destination array it must also exist in the source array.
11+
1312
![Dual ListBox](http://czeckd.github.io/angular-dual-listbox/images/dual-listbox.png)
1413

1514
## How to use?
@@ -28,8 +27,7 @@ import { AngularDualListBoxModule } from 'angular-dual-listbox';
2827
})
2928
export class AppModule {}
3029
```
31-
See also the [basic-dual-list-demo](https://github.com/czeckd/basic-dual-listbox-demo) for a sample project using this module.
32-
30+
See also the [basic-dual-list-demo](https://github.com/czeckd/basic-dual-listbox-demo) for a sample project using this module. Note that the default component uses Bootstrap 3 for styling and so the bootstrap.css would need to be included in the project for it to be styled correctly. That said, the styles can be overriden with your own style sheet or fully customized by extending the `DualListComponent` and providing a new template. For more details, see the section on **Extending** below.
3331

3432
## Usage
3533
Basic usage is:
@@ -38,22 +36,36 @@ Basic usage is:
3836
```
3937
The following parameters can be set on a dual-list:
4038
- **key** - The unique identifier field of each object in the `source` and
41-
`destination` arrays, default is ``_id``. (With a source of an array of strings, each string is its own id.)
39+
`destination` arrays, default is ``_id``. (Note: with a source of an array of strings, each string is its own id.)
4240
- **display** - The field of each object for displaying the object each the
43-
lists, default is ``_name``. (With a source of an array of strings, each string is its own display.)
41+
lists, default is ``_name``. Or, a function that returns a string that can be used for displaying an object. (Note: with a source of an array of strings, each string is its own display.)
4442
- **height** - The height of the lists, default is ``100px``.
45-
- **format** - A format object, default is ``{ add: 'Add', remove: 'Remove', all: 'All', none: 'None', direction: 'left-to-right', draggable: true }``
43+
- **format** - A format object, default is ``{ add: 'Add', remove: 'Remove', all: 'All', none: 'None', direction: 'left-to-right', draggable: true, locale: undefined }``
4644
- **filter** - A boolean whether or not to display a filter for the lists, default is ``false``.
4745
- **sort** - A boolean whether or not to keep the lists sorted, default is ``false``.
4846
- **compare** - A compare function to be used for sorting the lists. Note if
4947
sort is not set and compare is set, then sort will be set ``true``.
5048
- **source** - The source array of objects or strings for the list. (This is the universal, master list of all possible objects.)
51-
- **destination** The destination array of objects or strings selected from the source.
52-
Note, the ``destination`` array can have prexisting elements.
49+
- **destination** The destination array of objects or strings selected from the source. Note, the ``destination`` array can have prexisting elements.
5350
- **disabled** - The dual-list is disabled, default is ``false``.
5451

5552
For more usage examples, see the [`demo-app.component.ts`](https://github.com/czeckd/angular-dual-listbox/blob/master/app/demo-app.component.ts).
5653

54+
## Format
55+
The format object allows for the text for the add, remove, all, and none buttons to be set. It also can be used to set the layout direction with the source being on the left-hand side as the default, toggling drag-and-drop, and explicitly setting the locale for the filter string comparision. The default locale is undefined and will use host environment's current locale. An example format object:
56+
```typescript
57+
export class MyComponent {
58+
...
59+
format = { add: 'Tilføje', remove: 'Fjerne', all: 'Alle', none: 'Intet',
60+
direction: DualListComponent.LTR, draggable: true, locale: 'da' };
61+
...
62+
}
63+
```
64+
Then used in an html template:
65+
```html
66+
<dual-list [source]="source" [(destination)]="confirmed" [format]="format"></dual-list>
67+
```
68+
5769
## Extending
5870
The html template packaged with this component is based on Bootstap 3; however it can be overridden for customization. Here is an example:
5971

@@ -69,8 +81,8 @@ import { DualListComponent } from 'angular-dual-listbox';
6981
export class CustomDualListComponent extends DualListComponent {
7082
}
7183
```
72-
See [`dual-list.component.html`](https://github.com/czeckd/angular-dual-listbox/blob/master/lib/dual-list.component.html) and
73-
[`dual-list.component.css`](https://github.com/czeckd/angular-dual-listbox/blob/master/lib/dual-list.component.css) for template and style guidance.
84+
See [`dual-list.component.html`](https://github.com/czeckd/angular-dual-listbox/blob/master/lib/dual-list.component.html) and [`dual-list.component.css`](https://github.com/czeckd/angular-dual-listbox/blob/master/lib/dual-list.component.css) for template and style guidance.
85+
7486
There is also an Angular-CLI seed project, [custom-dual-listbox](https://github.com/czeckd/custom-dual-listbox), available with an example of a
7587
customized view and extended functionality.
7688

app/demo-app.component.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import { Component, OnInit } from '@angular/core';
22

33
import { DualListComponent } from 'angular-dual-listbox';
44

5-
65
@Component({
76
selector: 'demo-app',
8-
styles: [ '.form-group { margin-bottom: 16px; }', '.checkbox { margin-top: inherit }' ],
7+
styles: [ 'form { margin-top: 15px; }', '.checkbox { margin-top: inherit; }', 'ul.nav-tabs { cursor: pointer; }' ],
98
template: `
109
<div class="container-fluid">
1110
<p></p>
@@ -27,37 +26,43 @@ import { DualListComponent } from 'angular-dual-listbox';
2726
</div>
2827
2928
<div class="tab-pane" [class.active]="tab===2">
30-
<form class="form" style="margin:20px 0;">
31-
<label>Direction</label><br/>
29+
<form class="form">
3230
<div class="form-group">
31+
<label style="display:block;">Direction</label>
3332
<div class="btn-group">
3433
<button type="button" class="btn" [ngClass]="{ 'btn-primary' : sourceLeft, 'btn-default' : !sourceLeft }"
3534
(click)="swapDirection()">left-to-right</button>
3635
<button type="button" class="btn" [ngClass]="{ 'btn-primary' : !sourceLeft, 'btn-default' : sourceLeft }"
3736
(click)="swapDirection()">right-to-left</button>
3837
</div>
3938
</div>
39+
40+
<div class="form-group">
41+
<label>Enable drag-and-drop</label>
42+
<div class="checkbox">
43+
<label><input type="checkbox" [(ngModel)]="format.draggable" name="drag">draggable</label>
44+
</div>
45+
</div>
46+
47+
<div class="form-group">
48+
<label>Locale</label>
49+
<input class="form-control" [(ngModel)]="format.locale" name="locale">
50+
</div>
4051
<div class="form-group">
4152
<label>Add button</label>
42-
<input class="form-control col-sm-2" [(ngModel)]="format.add" name="addBtn">
53+
<input class="form-control" [(ngModel)]="format.add" name="addBtn">
4354
</div>
4455
<div class="form-group">
4556
<label>Remove button</label>
46-
<input class="form-control col-sm-2" [(ngModel)]="format.remove" name="rmBtn">
57+
<input class="form-control" [(ngModel)]="format.remove" name="rmBtn">
4758
</div>
4859
<div class="form-group">
4960
<label>All button</label>
50-
<input class="form-control col-sm-2" [(ngModel)]="format.all" name="allBtn">
61+
<input class="form-control" [(ngModel)]="format.all" name="allBtn">
5162
</div>
5263
<div class="form-group">
5364
<label>None button</label>
54-
<input class="form-control col-sm-2" [(ngModel)]="format.none" name="noneBtn">
55-
</div>
56-
<div class="form-group">
57-
<label>Enable drag-and-drop</label>
58-
<div class="checkbox">
59-
<label><input type="checkbox" [(ngModel)]="format.draggable" name="drag">draggable</label>
60-
</div>
65+
<input class="form-control" [(ngModel)]="format.none" name="noneBtn">
6166
</div>
6267
</form>
6368
</div>
@@ -114,7 +119,7 @@ export class DemoAppComponent implements OnInit {
114119
tab = 1;
115120
keepSorted = true;
116121
key:string;
117-
display:string;
122+
display:any;
118123
filter = false;
119124
source:Array<any>;
120125
confirmed:Array<any>;
@@ -216,9 +221,13 @@ export class DemoAppComponent implements OnInit {
216221
this.doReset();
217222
}
218223

224+
private stationLabel(item:any) {
225+
return item.station + ', ' + item.state;
226+
}
227+
219228
private useStations() {
220229
this.key = 'key';
221-
this.display = 'station'; // [ 'station', 'state' ];
230+
this.display = this.stationLabel;
222231
this.keepSorted = true;
223232
this.source = this.sourceStations;
224233
this.confirmed = this.confirmedStations;

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "../../node_modules/ng-packagr/package.schema.json",
33
"name": "angular-dual-listbox",
44
"description": "Angular 4+ component for a dual listbox control.",
5-
"version": "4.6.3",
5+
"version": "4.7.0",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/czeckd/angular-dual-listbox.git"

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-dual-listbox",
33
"description": "Angular 4+ component for a dual listbox control.",
4-
"version": "4.6.3",
4+
"version": "4.7.0",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/czeckd/angular-dual-listbox.git"
@@ -52,7 +52,7 @@
5252
"systemjs": "0.19.47",
5353
"ts-node": "^3.3.0",
5454
"tslint": "^5.8.0",
55-
"typescript": "~2.4.2",
55+
"typescript": "^2.6.2",
5656
"zone.js": "^0.8.18"
5757
}
5858
}

0 commit comments

Comments
 (0)