简体   繁体   English

如何在Vf页面中创建分组数据部分

[英]how to create sections of grouped data in Vf page

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

i need to display this info in Vf page with the Area as sections and name and make under it 我需要在Vf页面中以“区域”作为部分和名称显示此信息,并在其下进行显示

New york
Roger          Suzuki    
Bill           Audi      

Chicago
Mike           honda     
Kevin          GM        

Any pointers on how to get this would be of great help. 有关如何获得此指示的任何指示将大有帮助。

Thanks Prady 谢谢普拉迪

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);
    }
}

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: 现在, liAreas有了一个CArea对象列表, CArea对象都包含一个联系人列表,因此您可以在页面中遍历该列表:

<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>

Option #2: 选项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;}

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 . 现在,按照《 Visualforce开发人员指南》中“ 支持地图和列表 ”部分中的描述,使用动态Visualforce绑定。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM