Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Lets consider an example when we need to implement feature: On the list of categories user want to see average price of all products in each category.

Model

We will start with qcadoo model:

...

This is a realy simple model with 4 fields, the most important optins here are: activable, deletable, auditable, insertable, updatable set to false. As I mentioned before SQL views are readonly and this options account that fact. 

SQL View

Then we will create Next step is write some SQL script to create view in database.

...

Code Block
languagexml
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schema.qcadoo.org/view"
	xsi:schemaLocation="http://schema.qcadoo.org/view http://schema.qcadoo.org/view.xsd"
	name="productCategoriesList" modelName="productCategoryListItem" menuAccessible="true"     defaultAuthorizationRole="ROLE_PRODUCT_VIEW">	
	<component type="window" name="window" reference="window">
		<ribbon>
        	<group template="gridNewAndCopyAction" defaultAuthorizationRole="ROLE_PRODUCT_ADD"/>
        	<group template="gridActivateAndDeactivateAction" defaultAuthorizationRole="ROLE_PRODUCT_EDIT"/>
       	 	<group template="gridGenericExportAction" defaultAuthorizationRole="ROLE_PRODUCT_EXPORT"/>
		</ribbon>

		<component type="grid" name="productCategories" reference="grid" defaultAuthorizationRole="ROLE_PRODUCT_EDIT">
		    <option type="column" name="name" fields="name" link="true" />
		    <option type="column" name="productGroup" fields="productGroup" expression="#productGroup['name']"/>
		    <option type="column" name="productsAvgPrice" fields="productsAvgPrice" />

            <option type="order" column="name" direction="asc"/>
            <option type="correspondingView" value="basic/productCategoryDetails" />
            <option type="correspondingComponent" value="form" />
		    <option type="searchable" value="name,productGroup,productsAvgPrice"/>
		    <option type="orderable" value="name,productGroup,productsAvgPrice"/>
		    <option type="multiSearch" value="name,productGroup,productsAvgPrice"/>
		    <option type="fullscreen" value="true"/>
		    <option type="multiselect" value="true" />
		</component>

        <option type="fixedHeight" value="true" />
        <option type="header" value="false" />
	</component>
</view>

...

  • Removing from that grid should be disabled, because it will try to remove SQL View item and this is impossible. In this example you can see that there is no ribbon template called gridRemoveAction. Removing will be alloved allowed only from item details. If it is necessary to allove allow removing from grid then you will have to implement your own event listener for that. 

  • correspondingView of the grid can't use our SQL View as a source model. It will have to use productCategory model for that.  Our view use product category id as its own id field so there should not be conflict when you open product category details from our grid.  

...