Hi there,
Today i was adding a custom search box in flexgrid and i sucessfully did but have had this small problem with it. When i tried searching the text ... it started throwing error - ambigious field names. So to overcome the same i altered some part of the code and that 1 worked like a charm.
protected function set_ajax_list_queries($state_info = null) { if(!empty($state_info->per_page)) { if(empty($state_info->page) || !is_numeric($state_info->page) ) $this->limit($state_info->per_page); else { $limit_page = ( ($state_info->page-1) * $state_info->per_page ); $this->limit($state_info->per_page, $limit_page); } } if(!empty($state_info->order_by)) { $this->order_by($state_info->order_by[0],$state_info->order_by[1]); } if(!empty($state_info->search)) { if(!empty($this->relation)) foreach($this->relation as $relation_name => $relation_values) $temp_relation[$this->_unique_field_name($relation_name)] = $this->_get_field_names_to_search($relation_values); if($state_info->search->field !== null) { if(isset($temp_relation[$state_info->search->field])) { if(is_array($temp_relation[$state_info->search->field])) foreach($temp_relation[$state_info->search->field] as $search_field) $this->or_like($search_field , $state_info->search->text); else $this->like($temp_relation[$state_info->search->field] , $state_info->search->text); } elseif(isset($this->relation_n_n[$state_info->search->field])) { $escaped_text = $this->basic_model->escape_str($state_info->search->text); $this->having($state_info->search->field." LIKE '%".$escaped_text."%'"); } else { $this->like($state_info->search->field , $state_info->search->text); } } else { $columns = $this->get_columns(); $search_text = $state_info->search->text; if(!empty($this->where)) foreach($this->where as $where) $this->basic_model->having($where[0],$where[1],$where[2]); foreach($columns as $column) { if(isset($temp_relation[$column->field_name])) { if(is_array($temp_relation[$column->field_name])) { foreach($temp_relation[$column->field_name] as $search_field) { $this->or_like($search_field, $search_text); } } else { $this->or_like($temp_relation[$column->field_name], $search_text); } } elseif(isset($this->relation_n_n[$column->field_name])) { //@todo have a where for the relation_n_n statement } else { $this->or_like($this->basic_db_table . "." . $column->field_name, $search_text); } } } } }
protected function _get_field_names_to_search(array $relation_values) { if(!strstr($relation_values[2],'{')) return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2]; else { $relation_values[2] = ' '.$relation_values[2].' '; $temp1 = explode('{',$relation_values[2]); unset($temp1[0]); $field_names_array = array(); foreach($temp1 as $field) list($field_names_array[]) = explode('}',$field); for($i=0; $i < count($field_names_array); $i++) { $field_names_array[$i] = $this->_unique_join_name($relation_values[0]).'.'. $field_names_array[$i]; } return $field_names_array; } }
just altered / added the code which are bold / italic and underlined. Think this is worth a peice of code to add it in the new library itself to fix this search issue.
Hope this helps out a lot of other GC Users like me.
Happy GCing.