CGridView and quick search field.

Hi,

I’m trying to make a quick search field and work with CDataGrid. I’m ASP.NET developer so the ‘yii way’ is not always clear to me. How can I use the text value from my quick search field to limit the results in data grid.

What I have done already:

I’ve added quick search text field and submit button to my form, then I made a form model with my quick search field. In my action file I tried something like this:


$model = new UsersIndexForm;

        $gridModel = new UserRecord('search');


        if(isset($_GET['UserRecord']))

        {

            $gridModel->attributes = $_GET['UserRecord'];

        }


        $this->controller->render('index', array(

            'model' => $model,

            'gridModel' => $gridModel

        ));



and then in my template file:




<div class="searchBar">

		<?php echo CHtml::beginForm(); ?>

			<label>szukaj użytkownika</label>

			<?php echo CHtml::activeTextField($model, 'QuickSearch', array('class' => 'field small-field')) ?>

			<?php echo CHtml::submitButton('szukaj', array('class' => 'button')); ?>

		<?php echo CHtml::endForm(); ?>

	</div>

	<?php $this->widget('zii.widgets.grid.CGridView', array(

		/*'cssFile' => false,*/

		'dataProvider' => $gridModel->search($model->QuickSearch),



But this doesn’t seem to work. How can make this work?

try this in your view:




Yii::app()->clientScript->registerScript('search', "

$('.search-form form').submit(function(){

	$.fn.yiiGridView.update('YourGridID', {

		data: $(this).serialize()

	});

	return false;

});

");



if you used yiic or gii to generate a crud take a look at views/YourModel/admin.php