demogorgorn/yii2-sortable

Create sortable lists and grids using HTML5 drag and drop API for Yii 2.0.

Installs: 337

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 1

Open Issues: 1

Language:JavaScript

Type:yii2-extension

dev-master 2015-03-05 04:28 UTC

This package is auto-updated.

Last update: 2024-12-21 22:33:31 UTC


README

Yii2 wrapper for Sortable (https://github.com/RubaXa/Sortable), a minimalist JavaScript library for reorderable drag-and-drop lists on modern browsers and touch devices.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist demogorgorn/yii2-sortable "*"

or add

"demogorgorn/yii2-sortable": "*"

to the require section of your composer.json file.

How to use

On your view file.

// items data example
<?php 
	$items = [
		[
        	'content' => 'item-1',
            'options' => ['data-id' => 'optional data attribute'],
        ],
        [
        	'content' => 'item-name',
        ]
    ];

?>


<?php echo \demogorgorn\sortable\Sortable::widget([
		'varName' => 'editable',
		'editable' => true,
		'options' => [
			'class' => 'block__list',
			'id' => 'currencylist',
		],
		'items'=> $items,
		'clientOptions' => [
		'animation' => 150,
		'filter' => '.js-remove',
		'onFilter' => new \yii\web\JsExpression('function (evt) {
			var code = evt.item.getAttribute("data-id");
			evt.item.parentNode.removeChild(evt.item);
		}'),
		'onUpdate' => new \yii\web\JsExpression('function (evt) {
			// do something with js
		}'),
	],
]); ?>