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
SreejbSreejb 

How to bring repeated input text box under columns in page block table

Hi friends,

I am new to vf page development. My requirement is to bring 5*8 matrix format in page block table.Under Activity column I want bring repeated picklist for 5 rows. And for Sun to Sat columns to bring repeated input field text box for 5 rows. 

Here I have attached my code pls help on this.

My desired output is
User-added image

VF Page
 
<apex:page showHeader="false" sidebar="false" controller="timeentrydetails" >
    <apex:form >
        <apex:pageBlock title="Time Entry Details Page">
            <apex:pageBlockButtons location="top" >
                <apex:CommandButton value="Save"/>
                <apex:CommandButton value="Submitted"/>
                <apex:CommandButton value="Addrows"/>
                <apex:CommandButton value="Back"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!Time_entry_dt_list }" var="tm">
                <apex:column headerValue="Activity"  />
                <apex:column headerValue="SUN"  />
                <apex:column headerValue="MON"  />
                <apex:column headerValue="TUE"  />
                <apex:column headerValue="WED"  />
                <apex:column headerValue="THU"  />
                <apex:column headerValue="FRI"  />
                <apex:column headerValue="SAT"  />
                
            </apex:pageBlockTable>
        
        </apex:pageBlock>
    
    
    </apex:form>
      
 
</apex:page>

Controller
 
public class timeentrydetails {

Public Class Timeentrydetrow{
        Public Id Tmrowid {get;set;}
        Public String Activity {get;set;}
        Public Integer Hour {get;set;}
        
    
    }
    
    
    Public List<Timeentrydetrow> Time_entry_dt_list {get;set;}
    
    Public timeentrydetails(){
    
        Time_entry_dt_list = new List<Timeentrydetrow>();
        Timeentrydetrow tmd;
        
        for(Time_Entry_Detail__c tmed : [Select Activity__c,Hour__c from Time_Entry_Detail__c ]){
            Timeentrydetrow tr = new Timeentrydetrow();
        
        
        
        
        }
    


      
  
}


}
Regards
Jayabalaji


 
Best Answer chosen by Sreejb
SandhyaSandhya (Salesforce Developers) 
Hi Jayabalaji,

Please refer below sample code.

 
<apex:page controller="demo_EXTN">
<apex:form >
<apex:pageBlock >
 <apex:variable value="{!0}" var="j"/>
<apex:pageBlockTable id="row" value="{!matrix}" var="i">
    
    <apex:column headerValue="Quarter/Year">
        <apex:variable value="{!j+1}" var="j"/>
         <apex:repeat value="{!j}" var="q">
        <apex:outputText >Quarter YR{!q}</apex:outputText>
        </apex:repeat>              
    </apex:column>
    
    <apex:column headerValue="Actual Year 1">
    <apex:inputText />
    </apex:column>
    
    <apex:column headerValue="Actual Year 2">
    <apex:inputText />
    </apex:column>
    
    <apex:column headerValue="Actual Year 3">
    <apex:inputText />
    </apex:column>
    
    <apex:column headerValue="Actual Year 4">
    <apex:inputText />
    </apex:column>
    
       <!--apex:column >
        <apex:repeat id="columns" value="{!matrix}" var="k" >
          <td>{!k}</td>
        </apex:repeat>    
    </apex:column-->
    
 </apex:pageBlockTable>   
</apex:pageBlock>
</apex:form>
</apex:page>

Controller
 
public class demo_EXTN{ 
 public List<List<String>> matrix{get;set;}
 public demo_EXTN()
 {
 matrix = new List<List<String>>();
 List<Contact> contactList = [SELECT id, firstname FROM contact limit 4];
 system.debug(contactList); 
 List<Account> accountList = [select id, name FROM Account limit 4];
 system.debug(accountList);
 List<String> row = new List<String>(); // You know that the top left String will be empty 
 row.add('Acc/Contact'); // setup list of contact labels at top of grid/matrix 
 for(Integer i = 0; i<contactList.size(); i++)
 { 
 System.debug(contactList[i].firstname);    
 row.add(contactList[i].firstname);
 } // add the first row to the grid 
 matrix.add(row); 
 System.debug(matrix); // Setup list of account labels in rows of grid 
 for(Integer j=0; j<accountList.size(); j++)
 { 
 row = new List<String>();
 System.debug(accountList[j].name); 
 row.add(accountList[j].name); 
 matrix.add(row);   
 } 
 system.debug(matrix);
 } 
 }

Hope this helps you!

Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
 
Thanks and Regards
Sandhya

 

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi Jayabalaji,

Please refer below sample code.

 
<apex:page controller="demo_EXTN">
<apex:form >
<apex:pageBlock >
 <apex:variable value="{!0}" var="j"/>
<apex:pageBlockTable id="row" value="{!matrix}" var="i">
    
    <apex:column headerValue="Quarter/Year">
        <apex:variable value="{!j+1}" var="j"/>
         <apex:repeat value="{!j}" var="q">
        <apex:outputText >Quarter YR{!q}</apex:outputText>
        </apex:repeat>              
    </apex:column>
    
    <apex:column headerValue="Actual Year 1">
    <apex:inputText />
    </apex:column>
    
    <apex:column headerValue="Actual Year 2">
    <apex:inputText />
    </apex:column>
    
    <apex:column headerValue="Actual Year 3">
    <apex:inputText />
    </apex:column>
    
    <apex:column headerValue="Actual Year 4">
    <apex:inputText />
    </apex:column>
    
       <!--apex:column >
        <apex:repeat id="columns" value="{!matrix}" var="k" >
          <td>{!k}</td>
        </apex:repeat>    
    </apex:column-->
    
 </apex:pageBlockTable>   
</apex:pageBlock>
</apex:form>
</apex:page>

Controller
 
public class demo_EXTN{ 
 public List<List<String>> matrix{get;set;}
 public demo_EXTN()
 {
 matrix = new List<List<String>>();
 List<Contact> contactList = [SELECT id, firstname FROM contact limit 4];
 system.debug(contactList); 
 List<Account> accountList = [select id, name FROM Account limit 4];
 system.debug(accountList);
 List<String> row = new List<String>(); // You know that the top left String will be empty 
 row.add('Acc/Contact'); // setup list of contact labels at top of grid/matrix 
 for(Integer i = 0; i<contactList.size(); i++)
 { 
 System.debug(contactList[i].firstname);    
 row.add(contactList[i].firstname);
 } // add the first row to the grid 
 matrix.add(row); 
 System.debug(matrix); // Setup list of account labels in rows of grid 
 for(Integer j=0; j<accountList.size(); j++)
 { 
 row = new List<String>();
 System.debug(accountList[j].name); 
 row.add(accountList[j].name); 
 matrix.add(row);   
 } 
 system.debug(matrix);
 } 
 }

Hope this helps you!

Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
 
Thanks and Regards
Sandhya

 
This was selected as the best answer
SreejbSreejb
Hi Sandhya,

Thank you sandhya.... Your code more useful to me. Thanks a lot once again.
SreejbSreejb
Hi Sandhya,

Could u help on this requirement

I am new to vf page development. I have custom object Time_entry_details. Fields are Activity__c, Hour__c Date__c and lookup field to time_entry__c.

My vf Page look like this



Here Activity is picklist and other columns are (SUN to SAT) Input text boxes.

Scanario is

I select one activity and enter hours in monday wednesday text box in any row. If i click on save button it should save in time_entry_details__c object. while retriving the record it should show in the same text boxes.

Question is

How to refer each text box to object. I am thinking in background we need to give some unique reference.... like in excel cell (A1,A2,A3...Like). How to do like that? If i am wrong please lead me.

Herewith attached my vf page and controller. Please give me solution.
 
01<apex:page showHeader="false" sidebar="false" controller="timeentrydetails" >
02    <apex:form >
03        <apex:pageBlock title="Time Entry Details Page - {!$CurrentPage.parameters.startDate} - {!$CurrentPage.parameters.endDate} ">
04            <apex:pageBlockButtons location="top" >
05                <apex:CommandButton value="Save" action="{!save1}"/>
06                <apex:CommandButton value="Submitted"/>
07                <apex:CommandButton value="Addrows" action="{!addrows5}" reRender="row"/>
08                <apex:CommandButton value="Back" action="{!back1}"/>
09            </apex:pageBlockButtons>
10 
11              
12            <apex:pageBlockTable id="row" value="{!Tedt_list}" var="i">
13                <apex:column headerValue="Activity" >
14  
15                                    <apex:selectList multiselect="false" size="1" >
16                                        <apex:selectOption itemValue="--Select--" itemLabel="--Select--"/>
17                                        <apex:selectOption itemValue="Analysing"itemLabel="Analysing"/>
18                                        <apex:selectOption itemValue="Designing"itemLabel="Designing"/>
19                                        <apex:selectOption itemValue="Code Developing"itemLabel="Developing"/>
20                                        <apex:selectOption itemValue="Testing"itemLabel="Testing"/>
21                                    </apex:selectList>
22                               </apex:column>            
23 
24                       <apex:column headerValue="SUN">
25                       <apex:inputText size="10" />
26                       </apex:column>
27                        
28                       <apex:column headerValue="MON">
29                       <apex:inputText size="10" />
30                       </apex:column>
31                        
32                       <apex:column headerValue="TUE">
33                       <apex:inputText size="10" />
34                       </apex:column>
35                        
36                       <apex:column headerValue="WED">
37                       <apex:inputText size="10" />
38                       </apex:column>
39 
40                       <apex:column headerValue="THU">
41                       <apex:inputText size="10" />
42                       </apex:column>
43                        
44                       <apex:column headerValue="FRI">
45                       <apex:inputText size="10" />
46                       </apex:column>
47                        
48                       <apex:column headerValue="SAT">
49                       <apex:inputText size="10" />
50                       </apex:column>
51                       
52                 
53            </apex:pageBlockTable>
54         
55        </apex:pageBlock>
56     
57     
58    </apex:form>
59       
60  
61</apex:page>
Controller is
 
view sourceprint?
01public class timeentrydetails {
02 
03 
04    Public Class Tedrow{
05        Public Id Tedid {get;set;}
06        Public Id Teid {get;set;}
07        Public Date Date1{get;set;}
08        Public String Activity {get;set;}
09        Public Integer Hour {get;set;}
10        Public String Uniid {get;set;}
11        Public String Day {get;set;}
12     
13    }
14     
15   
16     public List<Time_Entry_Detail__c> Tedt_list {get;set;}
17     public List<Tedrow> Tedrow_list {get;set;}
18      
19    Public timeentrydetails(){
20     
21        string teid = apexpages.currentpage().getparameters().get('id').trim();
22        system.debug(teid);
23        string tesdate = apexpages.currentpage().getparameters().get('startDate');
24        system.debug(tesdate);
25        string teedate = apexpages.currentpage().getparameters().get('endDate');
26        system.debug(teedate);
27        Tedt_list = new List<Time_Entry_Detail__c>();
28        Tedrow_list = new List<Tedrow>();
29        Tedrow Tedrow_item = new Tedrow();
30         
31        if(teid!=null && teid!= '')
32        {
33            id timedetailid = (id) teid;
34            Tedt_list = [select id, name,Time_Entry__c,Activity__c,Date__c,Hour__c,Date_Day_value__c FROM Time_Entry_Detail__cwhere Time_Entry__c =:timedetailid and ownerid =:userinfo.getuserid() limit 150];
35        }
36 
37        for(integer i=Tedt_list.size();i<5;i++)
38        {
39             Time_Entry_Detail__c tedt = new Time_Entry_Detail__c();
40             Tedt_list.add(tedt);
41        }     
42   
43        for(Time_Entry_Detail__c ted_item  :Tedt_list )
44        {
45               Tedrow_item.Activity = ted_item.Activity__c;
46               Tedrow_item.Date1=ted_item.Date__c;
47               Tedrow_item.hour = (integer) ted_item.Hour__c;
48               Tedrow_item.day = ted_item.Date_Day_value__c; //checking if date is not null
49               Tedrow_item.Tedid = ted_item.id;
50               Tedrow_item.Teid = ted_item.Time_Entry__c;
51        }
52}
53 
54Public void addrows5(){
55      
56  for(integer i=0;i<5;i++)
57            {
58             Time_Entry_Detail__c tedt = new Time_Entry_Detail__c();
59             Tedt_list.add(tedt);
60            }
61}
62  
63 
64public PageReference back1() {
65 
66    PageReference reRend = new PageReference('/apex/timeentryexp');
67    reRend.setRedirect(false);
68    return reRend;
69 
70}
71 
72Public void save1(){
73 
74 
75 
76}
77 
78 
79 
80 
81 
82 
83 
84 
85}