Yii TbGridView - невозможно получить выбор из раскрывающегося списка, который будет сохранен при использовании пейджера

У меня проблемы с Yii (используя 1.1.x), я использую TbGridView для отображения представления сетки начальной загрузки с фильтрацией и пейджингом.

Однако он работает нормально, когда я выбираю из раскрывающегося списка «выполнено» («Да», «Нет» или «Все»), когда я пытаюсь использовать пейджер (например, чтобы перейти на страницу 2 набора записей страницы), он не сохраняет этот параметр «выполнено», который я выбрали. Так, например, если я выбрал «Нет» в раскрывающемся списке, а затем использую пейджер, он по какой-то причине не сохраняет значение «Нет» в раскрывающемся меню.

Может ли кто-нибудь предложить какие-либо идеи, поскольку я совершенно растерялся - хотя я бы предположил, что это связано с моей модельной функцией?

<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id'            => 'shoppurchases-grid',
'type'          => 'striped bordered condensed',
'dataProvider'  => $model->setPurchaseType('org')->search(10),
'filter'        => $model,
'template'      => '{summary}{items}{pager}',
'columns'       => array(
    array(
        'header'    =>  'Product Image',
        'value'     => 'CHtml::image($data->product->displayImageUrl, $data->product->product_name, array("class"=>"grid-image"))',
        'type'      => 'raw',
    ),
    array(
        'header'    =>  'Product',
        'name'      =>  'product.product_name',
        'value'     => '$data->product->product_name',
        'filter'    => CHtml::activeTextField($model, 'filterProductName', array('placeholder' => 'filter by product name')),
        'type'      => 'raw',
    ),
    array(
        'header'    =>  'Username',
        'name'      =>  'user.firstname',
        'value'     =>  '($data->user instanceof MyUser) ? CHtml::link(CHtml::encode($data->user->username),array("/carrot/myuser/update","id"=>$data->user->user_id)) : ""',
        'filter'    => CHtml::activeTextField($model, 'filterUserName', array('placeholder' => 'filter by username')),
        'type'      =>  'raw'
    ),
    array(
        'header'    =>  'Form Name',
        'name'      =>  'user.form_name',
        'value'     => '($data->user instanceof MyUser) ? $data->user->form_name : ""',
        'filter'    => CHtml::activeTextField($model, 'filterFormName', array('placeholder' => 'filter by form name')),
        'type'      => 'raw'
    ),
    array(
        'header'    =>  'Student',
        'name'      =>  'user.username',
        'value'     => '($data->user instanceof MyUser) ? $data->user->fullname : ""',
        'filter'    => CHtml::activeTextField($model, 'filterFirstName', array('placeholder' => 'filter by first name')),
        'type'      => 'raw'
    ),
    array(
        'header'    =>  'Price',
        'name'      =>  'price',
        'filter'    => BHtml::activeCompareableTextField($model, 'price', array('placeholder' => 'filter by price')),
        'type'      => 'raw'
    ),
    array(
        'header'    =>  'Purchase Time',
        'name'      =>  'purchase_time',
        'value'     => 'app()->dateFormatter->format("dd/MM/y H:m:s", $data->purchase_time)',
        'filter'    => BHtml::activeCompareableDateRange($model, 'purchase_time', array('placeholder' => 'filter by purchase time')),
        'type'      => 'raw'
    ),

    array(
        'header'    => 'Fulfilled',
        'name'      => 'fulfilled',
        'value'     => user()->hasAuth(Group::READ_ONLY, "equal") ? '$data->fulfilled ? "Yes" : "No"' : 'CHtml::activeCheckBox($data, "fulfilled")',
        'filter'    => CHtml::activeDropDownList($model, 'fulfilled', array(0 => 'No', 1 => 'Yes'), array('prompt' => 'All')),
        'type'      => 'raw',
        'htmlOptions'       => array('class' => 'align-center'),
        'headerHtmlOptions' => array('class' => 'align-center'),
    ),
    array(
        'name'              => 'organisation_name',
        'visible'           => ((user()->hasAuth(Group::GROUP_ADMIN, 'equal')) && (!user()->hasState('view_org'))),
        'filter'            => CHtml::activeDropDownList($model, 'organisation_id', CHtml::listData(Organisation::model()->leaChildren, 'organisation_id', 'organisation_name'), array('prompt'=>'All Schools')),
    ),
    array(
        'header'    =>  '',
        'value'     => 'CHtml::link("Refund", Yii::app()->controller->createUrl("bulk",array("id"=>$data->primaryKey)), array("class" => "btn btn-save", "name" => CHtml::activeName($data,"refunded")))',
        'type'      => 'raw',
        'visible'   => !user()->hasAuth(Group::READ_ONLY, "equal")
    ),
),

)); ?>

// Модель

    public function search() {
    // Warning: Please modify the following code to remove attributes that
    // should not be searched.

    $criteria = new CDbCriteria;

    $criteria->with = array('user', 'product');
    $criteria->compare('t.purchase_id', $this->purchase_id);
    $criteria->compare('t.user_id', $this->user_id, true);
    $criteria->compare('t.price', $this->price);
    $criteria->compare('t.form_price', $this->form_name);
    $criteria->compare('t.GUID', $this->GUID, true);
    $criteria->compare('t.refunded', $this->refunded);
    $criteria->compare('user.organisation_id', $this->organisation_id);

    ActiveRecord::addDateRange($criteria, 't.purchase_time', $this->purchase_time, false);
    if (strlen($this->fulfilled) > 0)
        $criteria->addCondition('fulfilled ' . (($this->fulfilled == 1) ? "IS NOT NULL" : "IS NULL"));

    //Related fields filtering
    $criteria->compare('product.product_name', $this->filterProductName, true);
    $criteria->compare('user.username', $this->filterUserName, true);
    $criteria->compare('user.firstname', $this->filterFirstName, true);
    $criteria->compare('user.form_name', $this->filterFormName, true);

    return new CActiveDataProvider($this->currentUserOrganisation(), array(
                'criteria' => $criteria,
                'sort' => array(
                    'defaultOrder' => 't.purchase_time DESC',
                    'attributes' => array(
                        'organisation_name' => array('asc' => 'o.organisation_name', 'desc' => 'o.organisation_name DESC'),
                        'user.username' => array('asc' => 'user.username', 'desc' => 'user.username desc'),
                        'user.form_name' => array('asc' => 'user.form_name', 'desc' => 'user.form_name desc'),
                        'user.firstname' => array('asc' => 'user.firstname', 'desc' => 'user.firstname desc'),
                        'product.product_name' => array('asc' => 'product.product_name', 'desc' => 'product.product_name desc'),
                        '*'
                    )
                )
            ));
}

person Zabs    schedule 10.01.2014    source источник
comment
Вы исправили свою проблему?   -  person Kumar V    schedule 11.01.2014


Ответы (1)


это было потому, что ваше выполненное значение равно 0, иногда, когда вы передаете 0 в php. он будет рассматривать его как ложный.

если возможно, установите его, как показано ниже, на странице просмотра

array('no' => 'No', 'yes' => 'Yes')

и тогда вам нужно изменить модель, а также.

$criteria->addCondition('fulfilled ' . (($this->fulfilled == 'yes') ? "IS NOT NULL" : "IS NULL"));

person chen    schedule 10.01.2014