لا يُظهر مربع إدخال مرشح Yii Cgridview سلسلة البحث بعد البحث

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

  •  21-12-2019
  •  | 
  •  

سؤال

أواجه مشكلة مع مربع إدخال عامل التصفية في CGridView.لذا يعرض الفلتر النتيجة الصحيحة بعد إدخال سلسلة البحث في مربع إدخال الفلتر والضغط على زر الإدخال، ولكن يتم مسح مربع الإدخال بعد ظهور النتيجة.وهذا يجعل الأمر غير مريح تمامًا للمستخدم أن يرى ما كان يبحث عنه لأن مربع إدخال المرشح فارغ بينما تعرض الشبكة نتائج البحث الصحيحة.

هنا هو الرمز.

اسم عرض الإدخال ::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، لكنه لا يعمل.

يرجى تقديم أي نوع من النصائح حول كيفية الاحتفاظ بقيمة سلسلة البحث في مربع التصفية.أوه، راجع للشغل الشبكات الأخرى على المواقع تعمل بشكل لا تشوبه شائبة، لذلك ليست مشكلة مع الملفات المفقودة.

شكرا مقدما ، maxx

هل كانت مفيدة؟

المحلول

حسنًا، لقد ارتكبت خطأً في كود renderpartial() الذي تسبب في هذا الخطأ.ببساطة التغيير'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