Altering meta datagrid templates to use the filtered datagrid control
Here are the steps you need to perform to make your code-generated QMetaDataGrids have automatic filtering.
If desired, pre-altered files for the changes made in steps 2-4 are attached below.
- Install the QFilteredDataGrid control
- Update /includes/qcodo/codegen/templates/db_orm/meta_datagrid/_main.tpl:
- to extend QFilteredDataGrid instead of QDataGrid.</li>
- Update /includes/qcodo/codegen/templates/db_orm/meta_datagrid/meta_add_column.tpl:
- To use a QFilteredDataGridColumn instead of a QDataGridColumn.
- So that it calls $objNode->SetFilteredDataGridColumnFilter?($objNewColumn); right at the end of the if(is_array($mixContent)'s else block.
- Update /includes/qcodo/codegen/templates/db_orm/meta_datagrid/meta_data_binder.tpl:
- Change the CountAll?() and LoadAll?() function calls to be QueryCount?($this->Conditions) and QueryArray?($this->Conditions, $objClauses) instead.
- Update /includes/qcodo/_core/framework/QQuery.class.php:
- We need to define that SetFilteredDataGridColumnFilter? function we called earlier.
- In the QQNode class, add:
public function SetFilteredDataGridColumnFilter(QFilteredDataGridColumn $col) { switch($this->strType) { case QType::Boolean: //List of true / false / any $col->FilterType = QFilterType::ListFilter; $col->FilterAddListItem("True", QQ::Equal($this, true)); $col->FilterAddListItem("False", QQ::Equal($this, false)); $col->FilterAddListItem("Set", QQ::IsNotNull($this)); $col->FilterAddListItem("Unset", QQ::IsNull($this)); break; case QType::String: case QType::DateTime: //LIKE $col->FilterType = QFilterType::TextFilter; $col->FilterPrefix = '%'; $col->FilterPostfix = '%'; $col->Filter = QQ::Like($this, null); break; case QType::Float: case QType::Integer: //EQUAL $col->FilterType = QFilterType::TextFilter; $col->Filter = QQ::Equal($this, null); break; case QType::Object: case QType::Resource: //this node points to a class, there's no way to know what to filter on $col->FilterType = QFilterType::None; $col->ClearFilter(); break; } }
Addendum
This will make all generated data grids filtered by default.
You can set FilterShow? to false on the datagrid, in order to hide the filter row, which should make it indistinguishable from a normal QDataGrid.
If you wish to avoid running all the other code, you can do something like: * Add a $blnIsFiltered type property to the MetaDataGrid? class * Add if($this->blnIsFiltered) before the $objNode->SetFilteredDataGridColumnFilter?($objNewColumn); line
Then, if you set your metadatagrid to not filtered before you call MetaAddColumn?, it won't set any filters for the columns
Attachments
- _main.tpl_.txt (1.3 kB) - added by VexedPanda 17 months ago.
- meta_add_column.tpl_.txt (4.0 kB) - added by VexedPanda 17 months ago.
- meta_data_binder.tpl__0.txt (1.4 kB) - added by VexedPanda 17 months ago.
