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
Satya413Satya413 

Display Summary Table in VF Page using apex:repeat

Hi, 

I am trying to display a summary table using apex:repeat. However, I am not getting the query right. Any help is appreciated. Below is my code.

Object: Time_Table__c  
Fields:  Class__c  --- lookup
             Time__c   --- lookup
             Day__c    --- picklist
             faculty_name__c  --- lookup
 
VF Page:
<apex:page controller="facultydetails_con" sidebar="false" >
<apex:form >
<center>
 <br></br><br></br>
  <b>Select Faculty </b>
  <apex:inputfield value="{!faculty.Faculty_Name__c}"/><br></br><br></br>
  <apex:commandButton value="Submit" action="{!submit}"/>  
  <apex:pageBlock >
   <apex:pageblockSection >
    <apex:repeat value="{!fd}" var="item">
     <apex:outputText value="{!item.Class__c}" />
    </apex:repeat>
   </apex:pageblockSection>
  </apex:pageBlock>
</center> 
</apex:form> 
</apex:page>

Controller:
 
public class facultydetails_con {

   public time_table__c faculty {get; set;}
   public list<time_table__c> fd {get; set;}
   
   public facultydetails_con()
   {
     list<time_table__c> fd = new list<time_table__c>();
   }
   public pagereference submit()
   {
    fd = [select class__c, day__c, faculty_name__c from time_table__c where faculty_name__c = :faculty.faculty_name__c];
    return null;
   }
}

Thank you,
Satya
Best Answer chosen by Satya413
hitesh90hitesh90
Hello Satya,

Try to use following sample code for your requirement.

Visualforce Page:
<apex:page controller="facultydetails_con" sidebar="false" >
    <apex:form >
        <center>
            <br></br><br></br>
            <b>Select Faculty </b>
            <apex:inputfield value="{!faculty.Faculty_Name__c}"/><br></br><br></br>
            <apex:commandButton value="Submit" action="{!submit}"/>  
            <apex:pageBlock >
                <apex:pageblockSection >
                    <apex:repeat value="{!fd}" var="item">
                        <apex:outputField value="{!item.Class__c}" />
                    </apex:repeat>
                </apex:pageblockSection>
            </apex:pageBlock>
        </center> 
    </apex:form> 
</apex:page>


Apex Class:
public class facultydetails_con {
    public time_table__c faculty {get; set;}
    public list<time_table__c> fd {get; set;}
    public facultydetails_con() {
        list<time_table__c> fd = new list<time_table__c>();
        faculty = new time_table__c();
    }
    public pagereference submit(){
        if(faculty.faculty_name__c != null){
            fd = [select class__c, day__c, faculty_name__c from time_table__c where faculty_name__c = :faculty.faculty_name__c];
        }
        return null;
    }
}

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/

All Answers

hitesh90hitesh90
Hello Satya,

Try to use following sample code for your requirement.

Visualforce Page:
<apex:page controller="facultydetails_con" sidebar="false" >
    <apex:form >
        <center>
            <br></br><br></br>
            <b>Select Faculty </b>
            <apex:inputfield value="{!faculty.Faculty_Name__c}"/><br></br><br></br>
            <apex:commandButton value="Submit" action="{!submit}"/>  
            <apex:pageBlock >
                <apex:pageblockSection >
                    <apex:repeat value="{!fd}" var="item">
                        <apex:outputField value="{!item.Class__c}" />
                    </apex:repeat>
                </apex:pageblockSection>
            </apex:pageBlock>
        </center> 
    </apex:form> 
</apex:page>


Apex Class:
public class facultydetails_con {
    public time_table__c faculty {get; set;}
    public list<time_table__c> fd {get; set;}
    public facultydetails_con() {
        list<time_table__c> fd = new list<time_table__c>();
        faculty = new time_table__c();
    }
    public pagereference submit(){
        if(faculty.faculty_name__c != null){
            fd = [select class__c, day__c, faculty_name__c from time_table__c where faculty_name__c = :faculty.faculty_name__c];
        }
        return null;
    }
}

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
This was selected as the best answer
Satya413Satya413
Hi Hitesh,

Thanks for your response. I am able to get the output now. However, I would like it to display it as a summary table and below is what I get.

User-added image

Thank you,
Satya
hitesh90hitesh90
Hello Satya,

Which layout do you want? can you please post the image of the expected layout.

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
Satya413Satya413
Hi Hitesh, 

Below is the screenshot. 

User-added image

Thank you,
Satya
SoumyaChakrabortySoumyaChakraborty
Can you please post the code of the summary table ie. the screenshot given by @Satya413.
Thanks in advance.