function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Money CareMoney Care 

How to Grouping record using VF page

Hi Guys

I have created a Vf page which like a custom report.but here my problem is i am not unable to grouping the record .see my  screenshot now i am getting this User-added image
 
public with sharing class PartyMaster {



    public List<MasterTest__c> accounts {get;set;}  
    public String[] Groups {get;set;}

    public MasterTest__c j { get; set; }
    
    public String Id { get; set; }
    public List<MasterTest__c> jb { get; set; }
    public String keyword { get; set; }
   
   //Dc 
    public PartyMaster (){
     jb=new List<MasterTest__c>();
    j=new MasterTest__c();
}

    public PageReference getid() {
    jb=[select ID, Name,Group__c,Master_Code__c,Date__c From MasterTest__c where Name=:id ];
        return null;
    }

     public PageReference getKey_search() {
 jb=[select ID, Name,Group__c,Master_Code__c,Date__c From MasterTest__c where Name=:id ];
        
        return null;
    }

//we need to assign some temp var,for data type
       public date startdate1;
       public date enddate1;
public PageReference go() {
    startdate1=j.Date__c;
    enddate1=j.Date__c;
    
    jb=[select  ID, Name,Group__c,Master_Code__c,Date__c From MasterTest__c where (Date__c>=:startdate1) AND (Date__c<=:enddate1)order by Date__c ASC];
    
        return null;
    }
    

}
}

--------------------------------------------------------------------------------------

<apex:page controller="PartyMaster" sidebar="false" showHeader="false"><style type="text/css" media="print">
@media print
{
#non-printable { display: none; }
#printable {
display: block;
width: 100%;
height: 100%;
}
}
</style>

<style type = "text/css">
        .colHeadr {text-align:center;}
        .colHeadrRight{
            text-align:right;
        }
        }
    </style>


 <apex:form id="dt">
  <apex:define name="body">
            <div style="width:1250px;margin: 0px auto 10px auto;background-color:Gray;border: 1px solid black;">
            <apex:image id="theImage" value="{!$Resource.Emami}" width="100" height="100"/>
            <apex:outputLink style="font-weight: bold;float:right;" value="{!URLFOR($Page.LoginPage)}"><b>Back To Home</b>
            </apex:outputLink>
  <apex:pageBlock title="BankBook Details To Search">
  
        
     <!---search By Date Range-->
    <b>Start Date</b><apex:inputField value="{!j.Date__c}"/>&nbsp;&nbsp;&nbsp;
     <b>End Date</b><apex:inputField value="{!j.Date__c}"/>
     <apex:commandButton value="Go" action="{!go}" reRender="dt" style="background:pink"/>
      <b><apex:commandLink id="printable"  onclick="JavaScript:window.print();" value="Print"/></b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <!---search By word-->
      <apex:inputText value="{!keyword}"/>
      <apex:commandButton value="Search By Group" action="{!getKey_search}" style="background:pink"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     
     
      <!---search By Id-->
      <apex:inputtext value="{!Id}"/>
      <apex:commandButton value="Search By Party" action="{!getid}" style="background:pink"/>
     
     <!---which fiels we want to display -->
   <apex:pageBlockSection columns="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   <apex:pageBlockTable var="jj" value="{!jb}" style="width:100%; font-size:10pt">
   <apex:column headerValue="Date" value="{!jj.Date__c}"/>
    <apex:column headerValue="Group" value="{!jj.Group__c}"/>
    
      <apex:column headerValue="Party Name" value="{!jj.Master_Code__c}"/>
      


     
   
    </apex:pageBlockTable>
   </apex:pageBlockSection>
  </apex:pageBlock>
 
  </div>
        </apex:define>
        <center><br/>
        <b><i style="font-size:10px;color:red;">Developed By GlobalNest IT Solution Pvt.Ltd. <a href="http://www.globalnest.com" target="_blank">[http://www.Globalnest.com]</a> </i></b>
    </center><br/>
    </apex:form>
</apex:page>
but i need this type of grouping  .,....

User-added image
 
Pradeep SinghPradeep Singh
Hi, refer below code, please make changes accordingly.
<apex:page controller="GroupingSoln">
    <apex:repeat value="{!groupMap}" var="grp">
        <apex:pageBlock title="{!grp}">
            <apex:dataList value="{!groupMap[grp]}" var="subgrp">
                <apex:outputText value="{!subgrp}"></apex:outputText>
            </apex:dataList>
        </apex:pageBlock>
    </apex:repeat>
</apex:page>

---------------------------------------------------------------------------------------------------------
public class GroupingSoln{
    
    public Map<string,List<string>> groupMap {get;set;}
    
    public GroupingSoln(){
        groupMap = new Map<string,List<string>>();
        groupMap.put('Group1',new List<string>{'abc','def'});
        groupMap.put('Group2',new List<string>{'123','456'});
        groupMap.put('Group3',new List<string>{'test','qwerty'});
    }
}
If this solves your problem, mark it as best answer. In case of any help, please let me know.