Code:
Ext.define('Product', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'price', type: 'float'},
{name: 'img', type:'string'}
],
hasMany: {model: 'Sales', name: 'sales'},
}
});
Ext.define('User', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'}
],
hasMany: {model: 'Sales', name: 'sales'},
}
});
Ext.define('Sales', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'id', type: 'int'},
{name: 'user_id', type: 'int'},
{name: 'product_id', type: 'int'},
{name: 'qty', type: 'float'},
{name: 'date', type: 'date'}
],
belongsTo: {model: 'Users'},
belongsTo: {model: 'Products'}
}
});
// -----------
Product data : data/prod.json
{ product: [
{id:'1', name:'Apple', price:'3.5'},
{id:'2', name:'Orange', price:'2.5'},
{id:'3', name:'Banana', price:'1.0'}
]}
User data: data/user.json
{ user: [
{id:'10', name:'Phil'},
{id:'20', name:'Spencer'}
]}
Sales data: data/sales.json
{ user: [
{id:'1', inv:'100', user_id:'10', product_id:'1', qty:'10', date: '2012-03-01'},
{id:'2', inv:'100', user_id:'10', product_id:'2', qty:'20', date: '2012-03-01'},
{id:'3', inv:'101', user_id:'20', product_id:'1', qty:'5', date: '2012-04-01'},
{id:'4', inv:'101', user_id:'20', product_id:'3', qty:'5', date: '2012-04-01'},
]}
// -----------
My questions is : how to generate a view nested list , group by inv, and having calculation like sql statement for multiple two fields from two models: sum(product.price x sale.qty) at second list, and total the sum at First List as Total : 106.50 as belows:
First List:
Total: 106.50
1. Inv: 100, user : Phil , Total : 85 << click to open second list
2. Inv: 101, user: Spencer, Total: 21.50
Second List.
1. 10 pcs of Apple = 35 << click to open product detial
2. 20 pcs of Orange = 50
Third Panel:
Product Image: img
Product name: Apple
Product price : 3.5
// -----
The Api document about data.association.HasMany and BelongsTo is clear but
I cannot find any example to generate multiple fields from multiple Models or
to create a Store from associated model(s).
Please help to classify the questions and how to do it in both sencha designer 2 and in sencha touch 2
Thanks in deed
FC