Revision #60 has been created by softark on Mar 7, 2019, 2:27:20 AM with the memo:
fixed broken markups
« previous (#59)
Changes
Title
unchanged
Filter & Sort by calculated/related fields in GridView Yii 2.0
Category
unchanged
Tutorials
Yii version
unchanged
2.0
Tags
unchanged
filter,gridview,faq,sort,DataColumn,yii2,wiki,grid,calculated
Content
changed
[...]
>Note: If you are looking at filtering and sorting by SUMMARY data from related tables, then refer [this wiki](http://www.yiiframework.com/wiki/679/filter-sort-by-summary-data-in-gridview-yii-2-0/).
Example Structure
-----------------
Let's say you have the following tables:
~~~
[sql]
/*
**Countries
*/**
```
MYSQLsql
CREATE TABLE `tbl_country` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'Unique country identifier',[...]
```
/* **Persons
*/**
```
MYSQLsql
CREATE TABLE `tbl_person` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'Unique person identifier',[...]
```
/* **Foreign Key
*/**
```
MYSQLsql
ALTER TABLE `tbl_person`
ADD CONSTRAINT `tbl_person_FK1`[...]
```
~~~
Prerequisites
-------------
Generate your models and CRUD via Gii. You should now have the following model classes generated:
1. **Person**: The base model for _tbl_person_[...]
Gridview Scenarios
------------------
Let's consider 2 scenarios you want to display in the GridView within the _index_ view generated for _Person_.
### Scenario 1: Calculated field from same table[...]
Scenario 1 Steps
----------------
**STEP 1:** Add a getter function to your base _Person_ model:
### Setup base model
```php
/* Getter for person full name */
public function getFullName() {[...]