在PhoneJS中分组平铺视图

时间:2014-06-14 13:53:12

标签: phonejs devextreme

我正在尝试将数据库中的产品展示到devexpress phonejs中的tileview项目中。成功地我可以将数据源中的项目加载到tileview中,但我想按类别名称对项目进行分组,并且真的不知道怎么做。任何帮助将不胜感激。

JS代码

return {
    sale: sale,
    departmansSource: {
        store: PosApplication.db.Departmans,
        select: ["DepartmanID", "DepartmanName"]
    },
    categoriesSource: {
        store: PosApplication.db.Categories,
        select: ["CategoryID", "CategoryName"]
    },
    productsSource: {
        store: PosApplication.db.Products,
        filter: ["DepartmanID","=", 2],
        select: ["ProductID", "ProductName", "DepartmanID", "DepartmanName", "CategoryID", "CategoryName"]
    },
    approversSource: {
        store: PosApplication.db.Approvers,
        select: ["ApproverId", "ApproverName"]
    },
    handleSave: handleSave,
    handleCancel: handleCancel,
    viewShown: handleViewShown,
    notifiy: notifiy
};

Html代码

<div id="urunlertile" data-bind="dxTileView: { height: '550', dataSource: productsSource, itemClickAction: notifiy, baseItemHeight: 70, baseItemWidth: 150, itemMargin: 3,  }">
            <div data-options="dxTemplate:{name:'item'}">                    

                <p><span data-bind="text: $data.CategoryName"></span></p>
                <p><span data-bind="text: $data.ProductName"></span></p>
                </div>                           
            </div>
            </div>  

1 个答案:

答案 0 :(得分:0)

您可以使用postProcess回调对dataSource中的数据进行分组/排序。

请参阅doc示例: http://js.devexpress.com/Documentation/Howto/Data_Layer/Data_Layer?version=14_1#Data_Layer_Data_Layer_Reading_Data_Data_Transformation_Post_Processing

请注意,dxTileView不支持显示分组数据。对数据进行分组,如

[{ key: "Category1", items: [{ name: "Product1" }, ...], ...] 

您可以在项目模板中放置嵌套的dxTileView以显示每个类别的产品。