YII CGRIDViewフィルタ入力ボックス検索後の検索文字列を表示しない

StackOverflow https://stackoverflow.com//questions/20014097

  •  21-12-2019
  •  | 
  •  

質問

CGridViewのフィルタ入力ボックスの問題に直面しています。そのため、フィルタ入力ボックスに検索文字列を入力してEnterキーを押した後、フィルタは正しい結果を示していますが、結果が表示された後に入力ボックスがクリアされています。これにより、グリッドに正しい検索結果が表示されている間に、フィルタ入力ボックスが空のため、ユーザーが検索していたことをユーザーに確認することが非常に不便です。

これはコードです。

エントリービュー名:: Newsreleases.php

    <?php
$this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'product-news-grid-' . $id,
    'itemsCssClass' => 'table table-striped',
    'htmlOptions' => array(
        'class' => 'news-datagrid',
    ),
    'dataProvider' => $dataProvider->searchProductNews($symbol), 
    'filter' => $dataProvider,
    'enableHistory' => false,
    'ajaxUpdate' => 'product-news-grid-' . $id,
    'ajaxUrl' => Yii::app()->createUrl('/realTime/AjaxUpdateProductNews'),
    'pager' => array(
        'header' => '',
        'cssFile' => false,
        'maxButtonCount' => 5,
        'selectedPageCssClass' => 'active',
        'hiddenPageCssClass' => 'disabled',
        'firstPageCssClass' => 'previous',
        'lastPageCssClass' => 'next',
        'firstPageLabel' => '<<',
        'lastPageLabel' => '>>',
        'prevPageLabel' => '<',
        'nextPageLabel' => '>',
    ),
    'summaryCssClass' => 'label label-warning',
    'columns' => array(
        array(
            'name' => 'headlines',
            'header' => 'Headlines',
            'value' => function($data) {
                return '<div class="product-news"> <a target="_blank" href="' . $data->link . '" > ' . $data->headlines . '</a></div>';
            },
            'type' => 'raw',
        ),
        array(
            'name' => 'publish_date',
            'header' => 'Date',
            'value' => function($data) {
                return '<span class="news-pub-date">' . $data->publish_date . '</span>';
            },
            'type' => 'raw',
        )
    )
));
?>


<!-- Now this script had to be included again in order to make the ajax sorting and pagination work, or else none of the ajax functionality is working. Remember when getting stuck with ajax update in grid views always use this script -->




<script type="text/javascript" src="/ProductAnalysis/assets/dd5f9a70/gridview/jquery.yiigridview.js"></script>
<script type="text/javascript">

    /*<![CDATA[*/
    jQuery(function($) {

        jQuery('[data-toggle=popover]').popover();

        jQuery('body').tooltip({
            "selector": "[data-toggle=tooltip]"
        });



        jQuery('#product-news-grid-' + $('#symbol-id').text()).yiiGridView({
            'ajaxUpdate': ['product-news-grid-' + $('#symbol-id').text()],
            'ajaxVar': 'ajax',
            'pagerClass': 'pagination',
            'loadingClass': 'grid-view-loading',
            'filterClass': 'filters',
            'tableClass': 'table table-striped',
            'selectableRows': 1,
            'enableHistory': false,
            'updateSelector': '{page}, {sort}',
            'filterSelector': '{filter}',
            'url': '/ProductAnalysis/index.php/realTime/AjaxUpdateProductNews',
            'pageVar': 'News_page',
            'afterAjaxUpdate': function() {
                jQuery('.popover').remove();
                jQuery('[data-toggle=popover]').popover();
                jQuery('.tooltip').remove();
                jQuery('[data-toggle=tooltip]').tooltip();
                $('#News_headlines').change(function() {
                    var inputVal = $(this).val();

                    $('#News_headlines').val(inputVal);

                });
            }
        });
    });
    /*]]>*/

</script>
.

AjaxUpdateProductNews

という名前のコントローラアクションです。
public function actionAjaxUpdateProductNews() {



    $dataProvider = new News();
    $dataProvider->unsetAttributes();

    if (isset($_GET['News'])) {

        $dataProvider->attributes = $_GET['News'];
    }





    $id = explode("-", $_GET["ajax"]);

    $realTime = RealTime::model()->findByPk($id[count($id) - 1]);

    $this->renderPartial('_newsView', array(

        'dataProvider' => new News(),
        'symbol' => $realTime->symbol,
        'id' => $realTime->id,
        'headlines' => $_GET['News']['headlines'],
        'publish_date' => $_GET['News']['publish_date']

    ));
}
.

とここではビュー_newsview

です。
  <?php




$this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'product-news-grid-'. $id,
    'itemsCssClass' => 'table table-striped',
    'htmlOptions' => array(
        'class' => 'news-datagrid',
    ),
    'dataProvider' => $dataProvider->searchProductNewsSymbol($symbol, $headlines, $publish_date), 
    'filter' => $dataProvider,
    'enableHistory' => false,
    'ajaxUpdate' => 'product-news-grid-'. $id,
    'ajaxUrl' => Yii::app()->createUrl('/realTime/AjaxUpdateProductNews'),
    'pager' => array(
        'header' => '',
        'cssFile' => false,
        'maxButtonCount' => 5,
        'selectedPageCssClass' => 'active',
        'hiddenPageCssClass' => 'disabled',
        'firstPageCssClass' => 'previous',
        'lastPageCssClass' => 'next',
        'firstPageLabel' => '<<',
        'lastPageLabel' => '>>',
        'prevPageLabel' => '<',
        'nextPageLabel' => '>',
    ),
    'summaryCssClass' => 'label label-warning',
    'columns' => array(
        array(
            'name' => 'headlines',
            'header' => 'Headlines',
            'value' => function($data) {
                return '<div class="product-news"> <a target="_blank" href="'. $data->link .'" > '. $data->headlines .'</a></div>';
            },
            'type' => 'raw',
        ),
        array(
            'name' => 'publish_date',
            'header' => 'Date',
            'value' => function($data) {
                return '<span class="news-pub-date">'. $data->publish_date .'</span>';
            },
            'type' => 'raw',
        )
    )
));

?>
.

今すぐ最初に結果が表示されていると言ったが、その結果が表示された後に入力ボックスがクリアされています。 jQueryの変更()ハンドラを使用して入力ボックスのvalを再挿入しようとしましたが、機能しません。

フィルタボックスに検索文字列の値を保持する方法については、どのようなアドバイスを提供してください。 OH、サイト上の他のグリッドが完璧に機能しているので、ファイルが不足している問題ではありません。

事前にありがとう、 MAXX

役に立ちましたか?

解決

OK私はこのエラーを引き起こしたrenderpartial code()に間違えました。単に変化する 'dataProvider' => new News()から'dataProvider' => $dataProviderへの問題を修正しました。それが同じ問題に直面している人を助けることを願っています。

作業コントローラコード

public function actionAjaxUpdateProductNews() {



    $dataProvider = new News();
    $dataProvider->unsetAttributes();

    if (isset($_GET['News'])) {

        $dataProvider->attributes = $_GET['News'];
    }





    $id = explode("-", $_GET["ajax"]);

    $realTime = RealTime::model()->findByPk($id[count($id) - 1]);

    $this->renderPartial('_newsView', array(

        'dataProvider' => $dataProvider,
        'symbol' => $realTime->symbol,
        'id' => $realTime->id,
        'headlines' => $_GET['News']['headlines'],
        'publish_date' => $_GET['News']['publish_date']

    ));
}
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top