Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SortableColumn is not visible #22

Open
rubenheymans opened this issue Oct 16, 2015 · 7 comments
Open

SortableColumn is not visible #22

rubenheymans opened this issue Oct 16, 2015 · 7 comments
Assignees
Labels

Comments

@rubenheymans
Copy link

I tried the most basic example, but I can't see any extra buttons in my Gridview

Behavior in model:

use arogachev\sortable\behaviors\numerical\ContinuousNumericalSortableBehavior;

[
                'class' => ContinuousNumericalSortableBehavior::className(),
                /*
                'scope' => function () {
                    return Team::find()->where(['location_id' => $this->location_id, 'department' => $this->department]);
                },
                */
                'sortAttribute' => 'position',
            ],

Index view:

use arogachev\sortable\grid\SortableColumn;

<div class="question-index" id="question-sortable">

    <?php // Gridview ?>
    <?php echo GridView::widget([
        'id' => 'sortable',
        'dataProvider'=> $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            [
                'class' => SortableColumn::className(),
                'gridContainerId' => 'question-sortable',
            ],
            'name',
            [
                'attribute' => 'location',
                'value' => 'location.name',
                'filter' => ArrayHelper::map(Location::find()->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'),
                'width' => '15%',
            ],
            [
                'attribute' => 'department',
                'value' => function($model) {
                    return $model->getDepartments($model->department);
                },
                'filter' => Team::getDepartments(),
                'width' => '15%',
            ],
            [
                'class' => 'kartik\grid\BooleanColumn',
                'attribute' => 'active',
                'vAlign'=> 'middle'
            ],
            [
                'class' => 'kartik\grid\ActionColumn',
                'template' => '{update} {delete} {active}',
                'buttons' => [
                    'active' => function ($url, $model) {
                        if ($model->active == true) {
                            $icon = 'glyphicon-eye-open';
                        } else {
                            $icon = 'glyphicon-eye-close';
                        }

                        return Html::a('<span class="glyphicon ' . $icon . '"></span>', $url, [
                            'title' => Yii::t('app', 'Toggle active'),
                            'data-pjax' => '0',
                            'data-toggleable' => 'true',
                            'data-toggle-id' => $model->id,
                            'data-toggle' => 'tooltip',
                        ]);
                    },
                ],
                'updateOptions' => ['title' => Yii::t('app', 'Update'), 'data-toggle' => 'tooltip'],
                'deleteOptions' => ['title' => Yii::t('app', 'Delete'), 'data-toggle' => 'tooltip'],
                'width' => '120px',
            ],
        ],
    ]);
    ?>
    </div>
@arogachev
Copy link
Owner

There are certain conditions in order to SortableColumn to be visible:

  • If access closure is specified, it should return true meaning current user have permissions to sort.
  • If you specified scope, according filter should be applied in GridView, otherwise we are dealing with mix of models from different scopes and sorting doesn't make sense.
  • If you specified sortableCondition, the opposite filter (not sortable) should not be applied. For example, if you set filter to show deleted models, it doesn't make sense to sort them too since they all have sort = 0.
  • You need to add sort to query by sortableAttribute (ascending). You can append sort?=position to applied filter.

In your case seems like you missed to add sort to getting models query.

It's a bit unclear from documentation, I will add these details into README later.

@arogachev
Copy link
Owner

Also you should rename <div class="question-index" id="question-sortable"> according to your model meaning, it's just an example. For example post-index and post-sortable.

@arogachev
Copy link
Owner

I'll consider adding an option to always show SortableColumn (except case when permissions check was failed).

@arogachev arogachev changed the title This is not working for me SortableColumn is not visible Oct 17, 2015
@arogachev arogachev self-assigned this Oct 17, 2015
@arogachev
Copy link
Owner

@rubenheymans Did you solve the problem?

@rubenheymans
Copy link
Author

I did not solve it because I'm using another sortable behavior.
This one looks better but I don't have time now to implement it.

@aelsaidy
Copy link

Hmm, got same problem , and I couldnt solve yet

@antdel
Copy link

antdel commented Oct 14, 2016

I solved this by explicitly setting the ActiveDataProvider property 'defaultSort', like this (in controller):

$dataProvider->sort = [ 'defaultOrder'=>['display_order'=>SORT_ASC] ];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants