Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I apply a CDataColumn filter to my CGridView so it displays only rows with a null-value?
    text
    copied!<p>I have a model with a boolean value, generated from a table like this:</p> <pre><code>CREATE TABLE receivable ( ... is_paid INTEGER DEFAULT NULL, ... ) </code></pre> <p>You should only take notice of the possible NULL value.</p> <p>I have a gii-generated Receivable.php-model and a simple CGridView, like this:</p> <pre><code>$dataProvider = $model-&gt;search(); $dataProvider-&gt;pagination = ['pageSize'=&gt;20]; $this-&gt;widget('zii.widgets.grid.CGridView', array( 'dataProvider'=&gt;$dataProvider, 'filter'=&gt;$model, 'columns'=&gt;array( 'id', [ 'name'=&gt;'is_paid', 'type'=&gt;'raw', 'value'=&gt;'($data-&gt;is_paid==1)?"PAID":"";', 'filter'=&gt;['1'=&gt;'PAID', '0'=&gt;'0'] ], 'someothercolumn', ['class'=&gt;'CButtonColumn'] ), ); </code></pre> <p>It should make sense so far? It does work fine I must say, with just one tiny problem - I want to allow filtering on null values as well!</p> <pre><code>'filter'=&gt;['1'=&gt;'PAID', '0'=&gt;'0', null=&gt;'null'] // This shows all records. 'filter'=&gt;['1'=&gt;'PAID', '0'=&gt;'0', ''=&gt;'null'] // This also shows all records. 'filter'=&gt;['1'=&gt;'PAID', '&lt;&gt;1'=&gt;'null or zero'] // This shows 0-records only. </code></pre> <p>Well, now I'm at a loss. Is there any way I can use the CDataColumn.filter to allow the user to filter on null values? (Only display rows where 'is_paid'==null)</p> <p>Edit: <strong>Values can be 1,0 or NULL, but the filter can only be applied for 1 or 0 (or show everything). How can I let the user display rows with null-values only?</strong></p> <p>Any help is much appreciated!</p>
 

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