Note that there are some explanatory texts on larger screens.

plurals
  1. POCGridview filter by dropdown using related model
    primarykey
    data
    text
    <p>I have two tables : User and UserProfile both are in relations. i.e UserProfile belongs to User. User table has column "is_active" which stores the active/inactive record of particular user in 0 and 1 format.</p> <p>Now I have one dropdown field which contains options Active (value 1) and Inactive (value 0) and I want to filter CGridview widget according to active and inactive users list.</p> <p>Following is what I am doing:</p> <pre><code>&lt;?php echo CHtml::dropDownList('UserProfile[is_active]', $model-&gt;user-&gt;is_active, array( '1'=&gt;"Active", '0'=&gt;"Inactive", ), array('onchange'=&gt;"$.fn.yiiGridView.update('yw0', {data: $(this).serialize()});") ); ?&gt; &lt;?php $this-&gt;widget('bootstrap.widgets.TbGridView', array( 'type' =&gt; 'striped bordered condensed', 'dataProvider' =&gt; $model-&gt;search(), 'filter' =&gt; $model, 'template' =&gt; '{pager}{items}', 'enableSorting' =&gt; true, 'columns' =&gt; array( 'title.name', array( 'name' =&gt; 'first_name', 'type' =&gt; 'raw', 'value' =&gt; 'CHtml::link($data-&gt;first_name,"/userProfile/$data-&gt;user_profile_id")' ), 'last_name', 'user.username', 'user.email', array( 'class' =&gt; 'bootstrap.widgets.TbButtonColumn', 'template' =&gt; '{update}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{delete}', ), ), 'pager' =&gt; array( 'header' =&gt; '', 'hiddenPageCssClass' =&gt; 'disabled', 'maxButtonCount' =&gt; 3, 'cssFile' =&gt; false, 'class' =&gt; 'CLinkPager', 'prevPageLabel' =&gt; '&lt;i class="icon-chevron-left"&gt;&lt;/i&gt;', 'nextPageLabel' =&gt; '&lt;i class="icon-chevron-right"&gt;&lt;/i&gt;', 'firstPageLabel' =&gt; 'First', 'lastPageLabel' =&gt; 'Last', ), 'pagerCssClass' =&gt; 'pagination', )); ?&gt; </code></pre> <p>Controller:</p> <pre><code>public function actionManage() { $model = new UserProfile('search'); $model-&gt;unsetAttributes(); // clear any default values if (isset($_GET['UserProfile'])) { $model-&gt;attributes = $_GET['UserProfile']; } $this-&gt;render('manage', array( 'model' =&gt; $model, )); } </code></pre> <p>And here is my Search method:</p> <pre><code>public function search() { $criteria = new CDbCriteria; $criteria-&gt;compare('first_name', $this-&gt;first_name, true); $criteria-&gt;compare('middle_name', $this-&gt;middle_name, true); $criteria-&gt;compare('last_name', $this-&gt;last_name, true); $criteria-&gt;with = array('user'); $criteria-&gt;join = 'LEFT JOIN AuthAssignment ON AuthAssignment.userid=user_id'; if (isset($_GET['employee'])): $criteria-&gt;addCondition("AuthAssignment.itemname &lt;&gt; 'Customer'"); $criteria-&gt;addCondition("user.is_active='$status'"); else: $criteria-&gt;addCondition("AuthAssignment.itemname = 'Customer'"); $criteria-&gt;addCondition("user.is_active='$status'"); endif; //Rights::getAssignedRoles(Yii::app()-&gt;session['user_id']); return new CActiveDataProvider($this, array( 'criteria' =&gt; $criteria, 'pagination' =&gt; array( 'pageSize' =&gt; 10, ), )); } </code></pre> <p>Here I want <code>$status</code> variable value to be dynamic as dropdown field change active or inactive.</p> <p>and when change dropdown option its showing following error:</p> <pre><code>TypeError: settings is undefined $grid.addClass(settings.loadingClass); </code></pre> <p>I am newbie in Yii and need help on this.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload