Getting started with nxt-sortablejs

Installing

npm install --save nxt-sortablejs sortablejs

Import Sortablejs module

import { SortablejsModule } from 'nxt-sortablejs'

@NgModule({
    ...
    imports: [
        ...
        SortablejsModule
    ]
})

If you want to cofigure global Sortablejs options, include SortablejsModule.forRoot in your application.

import { SortablejsModule } from 'nxt-sortablejs'

@NgModule({
    ...
    imports: [
        ...
        SortablejsModule.forRoot({
            animation: 150
        })
    ]
})

Use it in a template

<ul [nxtSortablejs]="items">
    <li *ngFor="let item of items">{{ item }}</li>
</ul>

Configuration options

InputTypeDefault valueDescription
[nxtSortablejs]SortableData<T>undefined

Input data, can be Array or FormArray

[sortablejsContainer]stringundefined

CSS selector for the sortable container

Mostly required when used with custom components which wrap items in multiple containers. In that case, this should be the selector for the direct HTML parent of sortable items.

[config]Optionsundefined

Sortablejs configuration

[cloneFunction]CloneFunction<T>undefined

A function invoked when cloning items from template dataset into target dataset

OutputTypeDescription
(init)Sortable

Initialised a new Sortablejs instance