Search code examples
kendo-ui-angular2

Sortable on array of objects not strings


How can I use component when source is not array of string, but rather array of objects?
All examples just show how to sort array of strings. But I want to sort rows from database, so I have at least 2 columns id and title.

<kendo-sortable [navigatable]="true" [data]="tasks"></kendo-sortable>

private tasks: Task[] = [{id: 1, title: "Test 1"}, {id: 2, title: "Test 2"}];

I am complete beginner in Angular so accept my apologise, if this is a dumb question.


Solution

  • You need to add a template to your sortable:

    <kendo-sortable [data]="palettes" >
        <template let-palette="item">
        {{palette.name}}
        </template>
    </kendo-sortable>
    

    Kendo documentation provides an example for this case : http://www.telerik.com/kendo-angular-ui/components/sortable/api/SortableComponent/#toc-data

    And the related plunker: http://plnkr.co/edit/3gSg2FnBqiZ7hy2cRzke?p=preview