NullRefExcep / yii2-datatables

Yii2 Widget for DataTables jQuery plug-in
http://www.datatables.net/
MIT License
72 stars 46 forks source link

extraColumn issue #62

Closed paskuale75 closed 4 years ago

paskuale75 commented 4 years ago

extraColumn array in applyOrder works like a charm but not in applyFilter() function, in _array($schema) conditions .. it seems to me that is the cause.

paskuale75 commented 4 years ago

applyFilter structure seems to be formed like below:

'applyFilter' => function ($query, $columns, $search) {
                    //custom search logic
                    $modelClass = $query->modelClass;
                    $schema = $modelClass::getTableSchema()->columns;
                    foreach ($columns as $column) {

                        $value = empty($search['value']) ? $column['search']['value'] : $search['value'];

                        if ($column['searchable'] == 'true' && array_key_exists($column['data'], $schema) !== false) {
                            $query->orFilterWhere(['like', $column['data'], $value]);
                        }else{
                            //filter on residenza (extraColumn) 
                            //be careful to use the name of the field you used in the main query->join (not extraColumn name)
                            $query->orFilterWhere(['like', 'cr.comune', $value]);
                        }
                    }
                    return $query;
                },
ZAYEC77 commented 4 years ago

So, does it work for you now?