Cgridview Fillter Issue

Hi am new to Yii,

Am having issue with filter with grid

View:-




<?php

$this->pageTitle = Yii::t('admin', 'Combobox');


$this->breadcrumbs = array(

	Yii::t('admin', 'Admin') => array('index'),

	Yii::t('admin', 'Combobox'),

);


/*$this->menu = array(

	array('label' => Yii::t('admin', 'Benutzer verwalten'), 'url' => array('users')),

	array('label' => Yii::t('admin', 'Combobox'), 'url' => array('combobox')),

	array('label' => Yii::t('admin', 'Form Code To Text'), 'url' => array('formCodeToText')),

);*/




?>


<h1><?php echo Yii::t('admin', 'Combobox'); ?></h1>

<br/>


	<?php 

		/*

		Code to display dynamic combobox type dropdown 

		$models = ComboboxData::model()->findAll(array('order' => 'type', 'distinct'=>true,));

		$list = CHtml::listData($models, 'type', 'type');

		echo CHtml::dropDownList('type', $type, 

              $list , array('empty' => 'Select a type')); */

		$select = '';	  

	    echo CHtml::dropDownList('type', $select, 

              array('cobj_type' => 'cobj_type', 'locspeciality' => 'locspeciality', 'locsubtype' => 'locsubtype', 'loctype' => 'loctype', 'perslink_role' => 'perslink_role', 'perslinkprio' => 'perslinkprio', 'perslinktp' => 'perslinktp', 'postgrad_train' => 'postgrad_train', 'salutation' => 'salutation', 'set_status' => 'set_status', 'softwcomp' => 'softwcomp', 'spec_focus' => 'spec_focus', 'speciality' => 'speciality', 'title' => 'title'),

              array('empty' => 'Select a type'));

 ?>


<?php


/**

 * Add JavaScript code

 */


// Add code for the dialog to add a new Code javascript code

Yii::app()->clientScript->registerScript('comboboxAddDialog', '

$("#dialog_add_combobox").dialog({

	autoOpen: false,

	height: "auto",

	width: "auto",

	modal: true,

	buttons: {

		' . Yii::t('combobox', 'OK') . ': function() {

			$.ajax({

				url: "' . $this->createUrl('combobox/create') . '",

				data: {

					id: $("#combobox_dialog_id").val(),					

					type: $("#type").val(),

					text: $("#add_text").val(),

					order: $("#add_order").val(),

					meaning: $("#add_meaning").val()

				},

				success: function(data) {

					if(data.search(/[a-z]/) == -1)		// Dummer Hack, um falschen Datastring im Erfolgsfall zu umgehen. Motto: Wenn ein Buchstabe drin vorkommt, wirds ne Fehlermeldung sein...

						$("#dialog_add_combobox").dialog("close");

					else

						alert(data);

				}

			});

		},

		' . Yii::t('comments', 'Abbrechen') . ': function() {

			$(this).dialog("close");

		}

	},

	close: function() {

		$("#combobox_dialog_id").val("");

		$("#add_text").val("");

		$("#add_order").val("");

		$("#add_meaning").val("");

		$.fn.yiiGridView.update("combobox-grid");

	}

});

');


/**

 *Code for visible items

 */


$panelListData = array(null => '');

foreach(FormSetOwners::model()->findAllByAttributes(array('owner_id' => $model->id)) as $temp)

{

	if($temp->set->type == 'panel')

		$panelListData[$temp->id] = $temp->set->name;

}


$this->beginWidget('zii.widgets.jui.CJuiDialog', array(

	'id' => 'dialog_add_combobox',

	'options' => array(

		'title' => Yii::t('combobox', 'Combobox detail'),

		'autoOpen' => false,

	),

));

	echo CHtml::hiddenField('combobox_dialog_id');

	//echo CHtml::label(Yii::t('comments', 'Panel'), 'add_comment_panel') . ' ' . CHtml::dropDownList('add_comment_panel', '', $panelListData) . '<br /><br />';

	echo CHtml::textField('add_text', '', array('size' => 30, 'maxlength' => 75)). '<br /><br />';

	echo CHtml::textField('add_order', '', array('size' => 10, 'maxlength' => 15)). '<br /><br />';

	echo CHtml::textField('add_meaning', '', array('size' => 30, 'maxlength' => 15));

$this->endWidget('zii.widgets.jui.CJuiDialog');

echo CHtml::link(Yii::t('combobox', 'Add Combobox'), '#', array('onclick' => '$("#dialog_add_combobox").dialog("open");return false;'));


$button_column = array(

	'class' => 'CButtonColumn',											// Buttons anzeigen

	'afterDelete' => 'function(link,success,data){if(success&&data.search(/[a-z]/) != -1)alert(data);}',		// Nach einer fehlgeschlagenen Löschoperation Fehlermeldung anzeigen

	'buttons' => array(

		'delete' => array(											// Neudefinition des Löschen-Buttons

			'label' => Yii::t('wholesalers', 'remove Combobox'),

			'url' => 'Yii::app()->createUrl("combobox/delete", array("id" => $data->id))',

		),

	),

	'template' => '',

);


$columns = array(

	$button_column,

	array(

		'name' => 'text',

		'type' => 'ntext',

		'value'=>'$data->text.\' \'.$data->text',

		'filter' => ComboboxData::model()->getListData('text'),

	),

	array(

		'name' => 'order',

		'type' => 'raw',

		//'value' =>  '$data->order_text ? $data->order_text->text : ""', 

		//'filter' => ComboboxData::model()->getListData('order'),

	),

	array(

		'name' => 'meaning',

		'type' => 'raw',

		'value' => 'CHtml::encode($data->meaning)', 

		'filter' => ComboboxData::model()->getListData('meaning'),

	),

);


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

	'id' => 'combobox-grid',

	'cssFile' => Yii::app()->baseUrl . '/css/gridview.css',

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

	'htmlOptions' => array('style' => 'cursor:pointer;'),

	'selectionChanged' => 'function(id){$("#" + id + " .items > tbody > tr").each(function(i){if($(this).hasClass("selected")){$("#add_text").val($("td", this).eq(1).html());$("#add_order").val($("td", this).eq(2).html());$("#add_meaning").val($("td", this).eq(3).html());$("#combobox_dialog_id").val($.fn.yiiGridView.getSelection(id));$("#dialog_add_combobox").dialog("open");return false;}});return false;}',

	'filter' => $model,

	'columns' => $columns,

));

?>



Controller




public function actionCombobox()

	{

		$model = new ComboboxData('search');

		$model->unsetAttributes();  // clear any default values

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

				$model->attributes=$_GET['ComboboxData'];

		}

		$this->render('combobox', array(

				'model'=>$model,

		));

	}



Model




<?php


/**

 * This is the model class for table "combobox_data".

 *

 * The followings are the available columns in table 'combobox_data':

 * @property integer $id

 * @property string $type

 * @property string $text

 * @property integer $order

 * @property string $meaning

 */

class ComboboxData extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @return ComboboxData the static model class

	 */

	public static function model($className = __CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'combobox_data';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		return array(

			array('type, text', 'required'),

			array('type, meaning', 'length', 'max' => 15),

			array('text', 'length', 'max' => 75),

			array('order', 'numerical', 'integerOnly' => true),

			array('id, type, text, order, meaning', 'safe', 'on' => 'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		return array(

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'id' => Yii::t('sys', 'ID'),

			'type' => Yii::t('sys', 'Typ'),

			'text' => Yii::t('sys', 'Text'),

			'order' => Yii::t('sys', 'Reihenfolge'),

			'meaning' => Yii::t('sys', 'Bedeutung'),

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		$criteria = new CDbCriteria;


		$criteria->compare('id', $this->id);

		$criteria->compare('type', $this->type, true);

		$criteria->compare('text', $this->text, true);

		$criteria->compare('order', $this->order);

		$criteria->compare('meaning', $this->meaning, true);


		return new CActiveDataProvider($this, array(

			'criteria' => $criteria,

			'pagination' => array(

                    'pageSize' => 20,

                ),


		));

	}


	/**

	 * Returns all combobox records of a given type in a format ready to use for drop down boxes

	 * @param string $type Type of the records to select

	 * @param boolean $inc_empty If set an empty entry is added at the beginning of the list

	 * @return Array mit Daten für Combobox

	 */

	public function getListData($type, $inc_empty = false)

	{

		// Search for the given type

		$result = $this->findAllByAttributes(array('type' => $type), array('order' => 't.order ASC, t.id ASC'));


		// Add empty entry if requested

		$ret = array();

		if($inc_empty)

			$ret[''] = '';


		// Show the value of the text column but use the value of the id column internally

		return $ret + CHtml::listData($result, 'id', 'text');

	}


	/**

	 * Returns the record with the given type and meaning

	 * @param string $type Type to look for

	 * @param string $meaning Meaning to look for

	 * @return The found record or null if none was found

	 */

	public function findByMeaning($type, $meaning)

	{

		return $this->findByAttributes(array('type' => $type, 'meaning' => $meaning));

	}


	/**

	 * Returns all records with the given type and meaning

	 * @param string $type Type to look for

	 * @param string $meaning Meaning to look for

	 * @return The records found or null if none was found

	 */

	public function findAllByMeaning($type, $meaning)

	{

		return $this->findAllByAttributes(array('type' => $type, 'meaning' => $meaning));

	}

	

}



Combobox Controller




<?php


/**

 * Provides the controller the entire combobox functionality

 */

class ComboboxController extends Controller

{

	/**

	 * Specifies the access control rules.

	 * This method is used by the 'accessControl' filter.

	 * @return array access control rules

	 */

	public function accessRules()

	{

		return array(

			array('allow',  // All users are allowed to create and delete wholesaler

				'actions' => array('create', 'delete'),

				'users' => array('*'),

			),

			array('deny',  // For all other or anything else prohibit

				'users' => array('*'),

			),

		);

	}


	/**

	 * Creates a new wholesaler

	*/

	public function actionCreate( $type, $text,  $order , $meaning, $id = -1)//

	{

		$model = ComboboxData::model()->findByAttributes(array('id' => $id, 'type' => $type));//

		

		// Is there not, then create new

		if($model == false)

		{

			$model = new ComboboxData;

			$model->type = $type;

			

		}


		// Werte reinschreiben			

		$model->text = $text;

		$model->order = $order;

		$model->meaning = $meaning;

		$model->save();

	

			

		// Save the entry

		if(!$model->save())

			echo Yii::t('Combobox', 'Failed to create the combobox.');


		// Done

		Yii::app()->end();

	}


	/**

	 * Deletes a wholesaler

	 * @param integer $ id ID of the deleted wholesaler

	 */

	public function actionDelete($id)

	{

		// Delete is only allowed in the form of a POST request

		if(Yii::app()->request->isPostRequest)

		{

			// Delete Entry

			$this->loadModel($id)->delete();


			// if AJAX request (triggered by deletion via index grid view), we should not redirect the browser

			if(!isset($_GET['ajax']))

				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));

		} else {

			// Keine POST-Anfrage -> Fehler

			throw new CHttpException(400, Yii::t('sys', 'Invalid request.'));

		}

	}


	/**

	 * Returns the data model based on the primary key given in the GET variable.

	 * If the data model is not found, an HTTP exception will be raised.

	 * @param integer the ID of the model to be loaded

	 */

	public function loadModel($id)

	{

		$model = ComboboxData::model()->findByPk($id);

		if($model === null)

			throw new CHttpException(404, Yii::t('sys', 'The requested page does not exist.'));

		return $model;

	}

}



Can any one help me

And what issue you have? maybe an error message? could you post it here possibly with callstack?

Hi

In Grid view filter data is not displaying

if i use below line

‘value’ => ‘$data->text_text ? $data->text_text->text : “”’,

am getting error

Property "ComboboxData.text_text" is not defined.

am not getting how to pass data ti filter.

could any one help me, plssssssssssssssssssss

Pls any one help me, where i am worng.

Am new yii, am not able to fine out where things wrong…

it seems there should be a relation named ‘text_text’ in ComboboxData model while there is no relations defined for this model:




        public function relations()

        {

                return array(

                );

        }



this is single table, there is no relationship with other table

Do you have table column text_text in your table?

what is that second text? are you calling relation table?

hi

in database, column name is text only

i dont know how to pass data to filter, i had searched in net.

i got that line from net…

other wise, can i use CHtml::listData for dropdown , it will work

yes - listData function is dedicated to transform array of model objects into simple associative array id=>value which can be used in dropdowns. You can also pass such array as grid column ‘filter’ and grid will show dropdown filter instead of text field.

ok thanks i ll try

hi, thanks for all.

now data is comming in drop down…

but if i select any one, grid data should reload.that is not happening…

If we want to use filter for grid, we have to write FiltersForm Model ??

Please any one reply… urgent… :unsure: