diff --git a/demo/src/app/components/sortable/demos/custom-item-template/custom-item-template.html b/demo/src/app/components/sortable/demos/custom-item-template/custom-item-template.html
new file mode 100644
index 0000000000..1e50c3960f
--- /dev/null
+++ b/demo/src/app/components/sortable/demos/custom-item-template/custom-item-template.html
@@ -0,0 +1,25 @@
+{{index}}: {{item.value}}
+
+
+
+
model: {{ itemStringsLeft | json }}
+
+
+
+
model: {{ itemStringsRight | json }}
+
diff --git a/demo/src/app/components/sortable/demos/custom-item-template/custom-item-template.ts b/demo/src/app/components/sortable/demos/custom-item-template/custom-item-template.ts
new file mode 100644
index 0000000000..a86ab11877
--- /dev/null
+++ b/demo/src/app/components/sortable/demos/custom-item-template/custom-item-template.ts
@@ -0,0 +1,19 @@
+import { Component } from '@angular/core';
+
+@Component({
+ selector: 'custom-item-template-demo',
+ templateUrl: './custom-item-template.html'
+})
+export class CustomItemTemplateDemoComponent {
+ public itemStringsLeft: any[] = [
+ 'Windstorm',
+ 'Bombasto',
+ 'Magneta',
+ 'Tornado'
+ ];
+
+ public itemStringsRight: any[] = [
+ 'Mr. O',
+ 'Tomato'
+ ];
+}
diff --git a/demo/src/app/components/sortable/demos/index.ts b/demo/src/app/components/sortable/demos/index.ts
index 889dc0fa57..2adabb092b 100644
--- a/demo/src/app/components/sortable/demos/index.ts
+++ b/demo/src/app/components/sortable/demos/index.ts
@@ -1,7 +1,12 @@
import { ComplexDatamodelDemoComponent } from './complex-datamodel/complex-datamodel.component';
import { SimpleItemsDemoComponent } from './simple-items/simple-items.component';
+import { CustomItemTemplateDemoComponent } from './custom-item-template/custom-item-template';
-export const DEMO_COMPONENTS = [SimpleItemsDemoComponent, ComplexDatamodelDemoComponent];
+export const DEMO_COMPONENTS = [
+ SimpleItemsDemoComponent,
+ ComplexDatamodelDemoComponent,
+ CustomItemTemplateDemoComponent
+];
export const DEMOS = {
complexDatamodel: {
@@ -11,5 +16,9 @@ export const DEMOS = {
simpleItems: {
component: require('!!raw-loader?lang=typescript!./simple-items/simple-items.component.ts'),
html: require('!!raw-loader?lang=markup!./simple-items/simple-items.component.html')
+ },
+ itemTemplate: {
+ component: require('!!raw-loader?lang=typescript!./custom-item-template/custom-item-template.ts'),
+ html: require('!!raw-loader?lang=markup!./custom-item-template/custom-item-template.html')
}
};
diff --git a/demo/src/app/components/sortable/sortable-section.component.html b/demo/src/app/components/sortable/sortable-section.component.html
index feef5b40f3..bfa6af4460 100644
--- a/demo/src/app/components/sortable/sortable-section.component.html
+++ b/demo/src/app/components/sortable/sortable-section.component.html
@@ -26,8 +26,9 @@ Contents
Usage
Examples
API Reference
@@ -53,6 +54,11 @@ Complex dat
+ Custom item template:
+
+
+
+
API Reference
diff --git a/demo/src/ng-api-doc.ts b/demo/src/ng-api-doc.ts
index d452e4c9db..c068dc7ec7 100644
--- a/demo/src/ng-api-doc.ts
+++ b/demo/src/ng-api-doc.ts
@@ -1510,6 +1510,11 @@ export const ngdoc: any = {
"type": "{ [key: string]: string; }",
"description": "
style object for item
\n"
},
+ {
+ "name": "itemTemplate",
+ "type": "TemplateRef",
+ "description": "used to specify a custom item template. Template variables: item and index;
\n"
+ },
{
"name": "placeholderClass",
"type": "string",
diff --git a/src/sortable/sortable.component.ts b/src/sortable/sortable.component.ts
index 5e11efa37b..8f9ec29c1b 100644
--- a/src/sortable/sortable.component.ts
+++ b/src/sortable/sortable.component.ts
@@ -1,5 +1,5 @@
import {
- Component, Input, Output, EventEmitter, forwardRef
+ Component, Input, Output, EventEmitter, forwardRef, TemplateRef
} from '@angular/core';
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
import { DraggableItem } from './draggable-item';
@@ -34,8 +34,12 @@ import { DraggableItemService } from './draggable-item.service';
(dragend)="resetActiveItem($event)"
(dragover)="onItemDragover($event, i)"
(dragenter)="cancelEvent($event)"
- >{{item.value}}
-`,
+ >
+
+
+{{item.value}}
+`,
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => SortableComponent),
@@ -76,6 +80,9 @@ export class SortableComponent implements ControlValueAccessor {
/** placeholder item which will be shown if collection is empty */
@Input() public placeholderItem: string = '';
+ /** used to specify a custom item template. Template variables: item and index; */
+ @Input() public itemTemplate: TemplateRef;
+
/** fired on array change (reordering, insert, remove), same as ngModelChange
.
* Returns new items collection as a payload.
*/