Code Monkey home page Code Monkey logo

yii2-sortable-widgets's Introduction

Yii2 Sortable widgets

Join the chat at https://gitter.im/kotchuprik/yii2-sortable-widgets

Implementation Rubaxa/Sortable for Yii2 widgets.

Supported:

  • GridView widget.

demo

Latest Stable Version Total Downloads Monthly Downloads Latest Unstable Version License

Usage

Create a new migration, change a parent to the migration class from the extension and specify the table name property:

class m140811_131705_Models_order extends \kotchuprik\sortable\migrations\Migration
{
    protected $tableName = 'models';
}

Add the sortable behavior to your model and specify the query property:

public function behaviors()
{
    return [
        'sortable' => [
            'class' => \kotchuprik\sortable\behaviors\Sortable::className(),
            'query' => self::find(),
        ],
    ];
}

Add the sorting action to your controller and specify the query property:

public function actions()
{
    return [
        'sorting' => [
            'class' => \kotchuprik\sortable\actions\Sorting::className(),
            'query' => \vendor\namespace\Model::find(),
        ],
    ];
}

If you're using another primary key (not 'id'), you must specify it in 'pk' parameter:

public function actions()
{
    return [
        'sorting' => [
            'class' => \kotchuprik\sortable\actions\Sorting::className(),
            'query' => \vendor\namespace\Model::find(),
            'pk' => 'modelField'
        ],
    ];
}

Add the column to your grid view and specify the sorting url like here:

echo \yii\grid\GridView::widget([
    'dataProvider' => $model->search(),
    'rowOptions' => function ($model, $key, $index, $grid) {
        return ['data-sortable-id' => $model->id];
    },
    'columns' => [
        [
            'class' => \kotchuprik\sortable\grid\Column::className(),
        ],
        'id',
        'title',
        'order',
    ],
    'options' => [
        'data' => [
            'sortable-widget' => 1,
            'sortable-url' => \yii\helpers\Url::toRoute(['sorting']),
        ]
    ],
]);

If cdn is not accessible in your country, you can use Sortable library from local dependencies:

...
    'columns' => [
        [
            'class' => \kotchuprik\sortable\grid\Column::className(),
            'useCdn' => false
        ],
        ...
    ],
...

yii2-sortable-widgets's People

Contributors

bmsrox avatar chuprik avatar et-nik avatar fellzo avatar gitter-badger avatar hryvinskyi avatar nismangulov avatar sluchznak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-sortable-widgets's Issues

checkbox states when sorting rows

Hello. Thank you for maintaining your plugin. I use it on my site in a few places and very useful.

I have an issue that I can't figure out. I have a Gridview widget that contains checkboxes in each row like:

'value' => function ($model, $key, $index, $grid) { $mid = $model->_id.'_'.$model->key; $chkbox = "<input id='{$mid}' class='selections' type='checkbox' name='selections[]' value='{$mid}'>"; return $chkbox; },

The strange behavior can be reproduced by:

  1. selecting row checkboxes
  2. de-select them
  3. drag a few to re-order
  4. result: the de-selected checkboxes will be selected again

It's kind of strange, but I'm not sure how to approach a fix. I tried to reproduce it on other jQuery based drag-sort examples, but can't reproduce. Do you have any ideas?

Thank you!

After save: position has wrong value

Sorry, but I found another bug.

in behavior->beforeInsert the first value is 1 for the order column.

I had this in my grid (like 1, 2, 3, 4, 5), but after saving it was 0,1,2,3,4.
Could you reproduce this? I think it is because of this line:
$model->{$this->orderAttribute} = $order;
$order is the key, beginning with 0.

Very strange, btw: in a grid w/o sorting, the data-key value of an tr is the id of the model, like here:
tr-ok
In a sortable grid it is like this:
tr-sortable
so data-sortable-id is the id of the model and data-key is the order column, I think?

Не заработало

Привет!
подскажи плиз в чем может быть проблема
Добавил все как написано, но почему то не хочет работать
В чем может быть проблема?

Wrong sort when enabled pagination

С пагинацией криво сортирует, так и задумано, что виджет можно использовать только без пагинации?

composer

Hello, how can I install this widget?

sortable within on "parent"

Hi,

i have one table having many rows which are "grouped" or "filtered" by a parent. I would love to use your extension, but I don't know how to make your extension with something like a "scope" - do you have an idea, how to manage this?

Thanks Philipp

way to make order field always start from zero vs. increment from highest order record

I wanted new records to be indexed by other owners (like "group_id") to always start from 0 instead of [$this->owner->{$this->orderAttribute} = $last->{$this->orderAttribute} + 1;]. I found that if I removed the public function behaviors(){...} from my MODEL and it prevented this behavior because it bypasses the beforeInsert() in the Sortable class. Just thought I'd share. Nice widget though.

So it looks like this:
id,group_id,order

  • 1,1,0
  • 2,1,1
  • 3,1,2
  • 4,1,3
  • 5,2,0
  • 6,2,1
  • 7,2,2
  • 8,2,3

Ошибка при использовании виджета

Доброго времени суток. при использовании Вашего виджета возникла проблема. Она не загружает скрипт Sortable.min.js.
Ошибки консоли

GET http://localhosti/admin/assets/8fa63dbc/Sortable.min.js net::ERR_ABORTED 404 (Not Found)
jquery.js:4055 Uncaught ReferenceError: Sortable is not defined
at HTMLTableSectionElement. (jquery.binding.js:37)
at Function.each (jquery.js:381)
at jQuery.fn.init.each (jquery.js:203)
at jQuery.fn.init.$.fn.sortableWidgets (jquery.binding.js:32)
at initSortableWidgets (sortable-widgets.js:2)
at HTMLDocument. (article:568)
at mightThrow (jquery.js:3762)
at process (jquery.js:3830)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.