kl83/yii2-grid-sortable-column

为Yii2 GridView提供的可排序列

v1.0.0 2017-07-04 08:50 UTC

This package is auto-updated.

Last update: 2024-09-29 04:42:48 UTC


README

Latest Stable Version Total Downloads License

用于排序行的GridView列类。看起来像这样

Preview

安装

安装此扩展的首选方式是通过composer

运行以下命令之一:

php composer.phar require kl83/yii2-grid-sortable-column ~1.0.0

或者将以下内容添加到你的composer.json文件的require部分:

"kl83/yii2-grid-sortable-column": "~1.0.0"

to the require section of your composer.json file.

使用方法

添加列

<?= GridView::widget([
    'id' => 'gridview',
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        [ 'class' => 'kl83\grid\SortableColumn' ],
        'title',
        'type',
        [ 'class' => 'yii\grid\ActionColumn' ],
    ],
]); ?>

监听GridView事件

$this->registerJs("
    $('#gridview').bind('sortablecolumn-sort', function ( e, data ) {
        // Sending data to the server
        $.get('/move-row', {
            itemId: data.itemId, // The key of the dragged row
            prevId: data.prevId, // The key of the previous row, false if the row is the first
            nextId: data.nextId  // The key of the next row, false if the row is the last
        });
    });
");

许可证

MIT许可证