Skip to main content
John Neff (Ring2Media) 님이 #Visualforce에 질문했습니다
Hello, 

Using this article (http://blog.jeffdouglas.com/2011/03/02/dynamically-group-display-query-results/) I have created a VF page and controller that dynamically groups custom object records by their associated campaign. 

It works great, except the campaigns in the array seem to display in random order on the VF page - and my users don't like that!

Is there a way that I can tweak my controller (shown below) to make the array of campaigns appear in alphabetical order? 

Here is my controller: 

 

public with sharing class AllSpotController{

public List <Job_Number__c> SPOT {get;set;}

public String[] campaigns {get;set;}

public void load() {

SPOT = [Select id, name, Thumbnail_URL__c, ISCI__c, Title__c, Project__c, Campaign__r.Name, Nets_Running__c, View_Link__c, Internal_Title__c, Legal__c from Job_Number__c where ISCI__c <> null];

Set<String> campaignSet = new Set<String>();

for (Job_Number__c j : SPOT)

campaignSet.add(j.Campaign__r.Name);

campaigns = new String[campaignSet.size()];

Integer i = 0;

for (String campaign : campaignSet) {

campaigns[i] = campaign;

i++;

}

}

}

Thanks in advance!

John
답변 9개
  1. 2016년 2월 24일 오후 9:19

    public with sharing class AllSpotController

    {

    public List <Job_Number__c> SPOT {get;set;}

    public list<String> campaigns {get;set;}

    public void load()

    {

    campaigns= new List<String>();

    SPOT = [Select id, name, Thumbnail_URL__c, ISCI__c, Title__c, Project__c, Campaign__r.Name, Nets_Running__c, View_Link__c, Internal_Title__c, Legal__c from Job_Number__c where ISCI__c <> null];

    Set<String> campaignSet = new Set<String>();

    for (Job_Number__c j : SPOT)

    campaignSet.add(j.Campaign__r.Name);

    for (String campaign : campaignSet)

    {

    campaigns.add(campaign);

    }

    campaigns.sort();

    }

    }

    i forgot to initialize the list ! :)
0/9000