By default the typeadmin tag dynamically generates a query to populate the grid based on the content type attribute. Sometimes you may want to bypass this mechanism and provide a custom query that is filtered in a special way or shows additional information that could only be shown by joining another table and so on. typeadmin allows you to create a custom query and pass it into the tag via the query attribute.
In the following example we have a custom content type called dmProject, but we only want to show those project content items that are currently active and we want to show a property value from a related content type in the grid (dmaccount.accountcode). So we generate a query with the appropriate filters in place and pass that in to override the default dynamically generated query.
<cfimport taglib="/farcry/farcry_core/tags/admin/" prefix="admin"> <cfimport taglib="/farcry/farcry_core/tags/widgets/" prefix="widgets"> <cfquery datasource="#application.dsn#" name="qProjects"> SELECT p.*, a.accountcode FROM dmproject p, dmaccount a WHERE p.accountid = a.objectid AND projStage = 'active' </cfquery> <!--- set up page header ---> <admin:header> <widgets:typeAdmin title="Active Projects" permissionset="news" typename="dmProject" bFilterCategories="false" query="#qProjects#" orderby="datetimelastupdated" bdebug="false" /> <!--- setup footer ---> <admin:footer>
Set bFilterCategories="false" for custom queries as filtering by categories can have unexpected results for custom queries
You may want to customise the column output by using one of the column customisation options available in typeadmin, to show off additional columns you have introduced into the query. Learn more at typeadmincolumn and typeadmin default columns.