Skip to content

Commit

Permalink
Merge pull request #23 from wa1kb0y/master
Browse files Browse the repository at this point in the history
Added "moveItem" setting
  • Loading branch information
richardfan1126 authored Jul 25, 2020
2 parents e7726b4 + 087cd2b commit eea20e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,16 @@ use richardfan\sortable\SortableGridView;
'sortUrl' => Url::to(['sortItem']),
'sortingPromptText' => 'Loading...',
'failText' => 'Fail to sort',
'moveItem' => '.moveItem',

'columns' => [
[
'content' => function(){
return "<span class='glyphicon glyphicon-resize-vertical'></span>";
},
'contentOptions' => ['style'=>'cursor:move;', 'class' => 'moveItem'],
],

// Data Columns
],
]); ?>
Expand Down
9 changes: 9 additions & 0 deletions SortableGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ class SortableGridView extends GridView {
*/
public $failText = 'Fail to sort';

/**
* (optional) Element which need to drag to start sortable.
* Empty if need drag by whole row.
*
* @var string
*/
public $moveItem = '';

public function init(){
parent::init();

Expand Down Expand Up @@ -83,6 +91,7 @@ public function run(){
'action' => $this->sortUrl,
'sortingPromptText' => $this->sortingPromptText,
'sortingFailText' => $this->failText,
'moveItem' => $this->moveItem,
'csrfTokenName' => \Yii::$app->request->csrfParam,
'csrfToken' => \Yii::$app->request->csrfToken,
];
Expand Down
4 changes: 3 additions & 1 deletion assets/js/sortable-grid-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
action: 'sortItem',
sortingPromptText: 'Loading...',
sortingFailText: 'Fail to sort',
moveItem: '',
csrfTokenName: '',
csrfToken: '',
};
Expand All @@ -16,13 +17,14 @@
var regex = /items\[\]\_(\d+)/;

$('#' + options.id + ' .sortable-grid-view tbody').sortable({
handle: options.moveItem,
update : function () {
$('#' + options.id + '-sorting-modal').modal('show');
//serial = $('#' + options.id + ' .sortable-grid-view tbody').sortable('toArray', {attribute:'id'});
serial = [];


$('#' + options.id + ' .sortable-grid-view tbody .ui-sortable-handle').each( function() {
$('#' + options.id + ' .sortable-grid-view tbody.ui-sortable tr').each( function() {
//console.log($(this).data('key'));
serial.push($(this).data('key'));
});
Expand Down

0 comments on commit eea20e7

Please sign in to comment.