title: Yii Cgridview Filter Input Box Not Showing Search String After Searching
body: <p>i'm facing an issue with the filter input box in CGridView. So the filter is showing the correct result after entering the search string in the filter input box and hitting enter, but the input box is getting cleared after the result is being shown. This makes it quite inconvenient for the user to see what they was searching for because the filter input box is empty while the grid shows the correct search results.</p>
  
  <p>Here are the code.</p>
  
  <p>entry view name ::newsReleases.php</p>
  
  <pre><code>    &lt;?php
  $this-&gt;widget('bootstrap.widgets.TbGridView', array(
      'id' =&gt; 'product-news-grid-' . $id,
      'itemsCssClass' =&gt; 'table table-striped',
      'htmlOptions' =&gt; array(
          'class' =&gt; 'news-datagrid',
      ),
      'dataProvider' =&gt; $dataProvider-&gt;searchProductNews($symbol), 
      'filter' =&gt; $dataProvider,
      'enableHistory' =&gt; false,
      'ajaxUpdate' =&gt; 'product-news-grid-' . $id,
      'ajaxUrl' =&gt; Yii::app()-&gt;createUrl('/realTime/AjaxUpdateProductNews'),
      'pager' =&gt; array(
          'header' =&gt; '',
          'cssFile' =&gt; false,
          'maxButtonCount' =&gt; 5,
          'selectedPageCssClass' =&gt; 'active',
          'hiddenPageCssClass' =&gt; 'disabled',
          'firstPageCssClass' =&gt; 'previous',
          'lastPageCssClass' =&gt; 'next',
          'firstPageLabel' =&gt; '&lt;&lt;',
          'lastPageLabel' =&gt; '&gt;&gt;',
          'prevPageLabel' =&gt; '&lt;',
          'nextPageLabel' =&gt; '&gt;',
      ),
      'summaryCssClass' =&gt; 'label label-warning',
      'columns' =&gt; array(
          array(
              'name' =&gt; 'headlines',
              'header' =&gt; 'Headlines',
              'value' =&gt; function($data) {
                  return '&lt;div class="product-news"&gt; &lt;a target="_blank" href="' . $data-&gt;link . '" &gt; ' . $data-&gt;headlines . '&lt;/a&gt;&lt;/div&gt;';
              },
              'type' =&gt; 'raw',
          ),
          array(
              'name' =&gt; 'publish_date',
              'header' =&gt; 'Date',
              'value' =&gt; function($data) {
                  return '&lt;span class="news-pub-date"&gt;' . $data-&gt;publish_date . '&lt;/span&gt;';
              },
              'type' =&gt; 'raw',
          )
      )
  ));
  ?&gt;
  
  
  &lt;!-- 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 --&gt;
  
  
  
  
  &lt;script type="text/javascript" src="/ProductAnalysis/assets/dd5f9a70/gridview/jquery.yiigridview.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
      /*&lt;![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);
  
                  });
              }
          });
      });
      /*]]&gt;*/
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Here is the controller action named AjaxUpdateProductNews</p>
  
  <pre><code>public function actionAjaxUpdateProductNews() {
  
  
  
      $dataProvider = new News();
      $dataProvider-&gt;unsetAttributes();
  
      if (isset($_GET['News'])) {
  
          $dataProvider-&gt;attributes = $_GET['News'];
      }
  
  
  
  
  
      $id = explode("-", $_GET["ajax"]);
  
      $realTime = RealTime::model()-&gt;findByPk($id[count($id) - 1]);
  
      $this-&gt;renderPartial('_newsView', array(
  
          'dataProvider' =&gt; new News(),
          'symbol' =&gt; $realTime-&gt;symbol,
          'id' =&gt; $realTime-&gt;id,
          'headlines' =&gt; $_GET['News']['headlines'],
          'publish_date' =&gt; $_GET['News']['publish_date']
  
      ));
  }
  </code></pre>
  
  <p>and here is the view _newsView </p>
  
  <pre><code>  &lt;?php
  
  
  
  
  $this-&gt;widget('bootstrap.widgets.TbGridView', array(
      'id' =&gt; 'product-news-grid-'. $id,
      'itemsCssClass' =&gt; 'table table-striped',
      'htmlOptions' =&gt; array(
          'class' =&gt; 'news-datagrid',
      ),
      'dataProvider' =&gt; $dataProvider-&gt;searchProductNewsSymbol($symbol, $headlines, $publish_date), 
      'filter' =&gt; $dataProvider,
      'enableHistory' =&gt; false,
      'ajaxUpdate' =&gt; 'product-news-grid-'. $id,
      'ajaxUrl' =&gt; Yii::app()-&gt;createUrl('/realTime/AjaxUpdateProductNews'),
      'pager' =&gt; array(
          'header' =&gt; '',
          'cssFile' =&gt; false,
          'maxButtonCount' =&gt; 5,
          'selectedPageCssClass' =&gt; 'active',
          'hiddenPageCssClass' =&gt; 'disabled',
          'firstPageCssClass' =&gt; 'previous',
          'lastPageCssClass' =&gt; 'next',
          'firstPageLabel' =&gt; '&lt;&lt;',
          'lastPageLabel' =&gt; '&gt;&gt;',
          'prevPageLabel' =&gt; '&lt;',
          'nextPageLabel' =&gt; '&gt;',
      ),
      'summaryCssClass' =&gt; 'label label-warning',
      'columns' =&gt; array(
          array(
              'name' =&gt; 'headlines',
              'header' =&gt; 'Headlines',
              'value' =&gt; function($data) {
                  return '&lt;div class="product-news"&gt; &lt;a target="_blank" href="'. $data-&gt;link .'" &gt; '. $data-&gt;headlines .'&lt;/a&gt;&lt;/div&gt;';
              },
              'type' =&gt; 'raw',
          ),
          array(
              'name' =&gt; 'publish_date',
              'header' =&gt; 'Date',
              'value' =&gt; function($data) {
                  return '&lt;span class="news-pub-date"&gt;'. $data-&gt;publish_date .'&lt;/span&gt;';
              },
              'type' =&gt; 'raw',
          )
      )
  ));
  
  ?&gt;
  </code></pre>
  
  <p>Now like i said the filter is showing the result, but the input box is getting cleared after it shows the result. I tried to reinsert the val in the input box using jQuery's change() handler, but it doesn't works.</p>
  
  <p>Please provide any sort of advice on how to retain the search string value in the filter box. Oh, btw other grids on the sites are working flawlessly, so its not a problem with missing files.</p>
  
  <p>Thanks in advance,
  Maxx </p>