DragSort is a helper to sort a list per drag and drop.
Function DragSort returns an object with all required function. The function dragProps of the object can inject all html attributes like draggable, onDragStart and so on.
- Description:
DragSort is a helper to sort a list per drag and drop.
Function DragSort returns an object with all required function. The function dragProps of the object can inject all html attributes like draggable, onDragStart and so on.
- Source:
- Version:
- version 2.0 modified for vanjs
Properties:
| Name | Type | Description |
|---|---|---|
dragProps(index) |
function | return the html attributes for element |
Example
Usage example
import van from 'vanjs-core';
import DragSort from 'vanjs-bootstrap/drag-sort';
var list = ["A","B","C"];
const setList = v => list = v;
function MyList ({list, setList, ...props}) {
const drag = DragSort(list, setList);
const items = list.map( (item,index) => {
return van.tags.li({
class: "list-group-item",
...drag.dragProps(index)
},
item
)
});
return van.tags.ul({class: "list-group", ...props}, ...items)
}
Parameters:
| Name | Type | Description |
|---|---|---|
list |
Array.<*> | array to be sorted |
setList |
function | callback function to store reordered list
|
Returns:
- Type
- Object