如何在 Vf 页面中创建分组数据的部分 [英] how to create sections of grouped data in Vf page

查看:35
本文介绍了如何在 Vf 页面中创建分组数据的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下数据的列表

I have a List with data below

customer name  Make      Area
Mike           honda     Chicago
Kevin          GM        Chicago
Bill           Audi      New York
roger          Suzuki    New York

我需要在 Vf 页面中显示此信息,并将区域作为部分和名称并在其下制作

i need to display this info in Vf page with the Area as sections and name and make under it

New york
Roger          Suzuki    
Bill           Audi      

Chicago
Mike           honda     
Kevin          GM        

有关如何获得此信息的任何指示都会有很大帮助.

Any pointers on how to get this would be of great help.

谢谢普拉迪

推荐答案

我可以想到两种可能的方法来做到这一点,第一种(绝对有效)是在您的控制器中使用包装类,如下所示:

I can think of two potential ways to do this, the first (which definitely works) would be to use a wrapper class in you controller like so:

public class CArea
{
    public list<Contact> liContacts {get; set;}
    public string strAreaName {get; set;}

    public CArea(Contact sContact)
    {
        strAreaName = sContact.City;
        liContacts = new list<Contact>{sContact};
    }
}

public list<CArea> liAreas {get; set;}
private map<string, CArea> mapAreas = new map<string, CArea>();

// **snip**
// fill up the list: (assuming contacts)

for(Contact sContact : myContactList}
{
    if(mapAreas.get(sContact.City) == null)
    {
        mapAreas.put(sContact.City, new CArea(sContact));
        liAreas.add(mapAreas.get(sContact.City);
    }
    else
    {
        mapAreas.get(sContact.City).liContacts.add(sContact);
    }
}

现在 liAreas 有一个 CArea 对象列表,每个对象都包含一个联系人列表,因此您可以在页面中遍历此列表:

Now liAreas has a list of CArea objects, with each one containing a list of contacts, so you can loop over this list in your page:

<apex:repeat var="a" value="{!liAreas}">
    <apex:outputText value="{!a.strName}"/>
    <apex:repeat var="c" value="{!a.liContacts}">
        <apex:outputText value="{!c.FirstName c.LastName}"/>
    </apex:repeat>
</apex:repeat>

选项 2:

这可能要简单得多,但我还没有尝试过像这样的两个级别的动态绑定.与之前的设置类似,但使用区域地图来列出联系人:

This is potentially a lot simpler, but I've not tried dynamic bindings with two levels like this. Similar setup to before, but use a map of areas to list of contacts:

public map<string, list<Contact>> mapAreaToContacts {get; set;}

填充这个应该很容易,和上面的代码非常相似.现在使用 Visualforce 开发人员指南 中所述的动态 Visualforce 绑定,在支持地图和列表部分.

Filling this should be easy enough, very similar to the above code. Now use dynamic Visualforce bindings as described in the Visualforce Developer's Guide, in the section Supporting Maps and Lists.

祝你好运!

这篇关于如何在 Vf 页面中创建分组数据的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆