i have a VF page code
<apex:pageBlockSection collapsible="false" columns="2" >
<apex:inputField value="{!Opp.field1__c}"/>
<apex:inputField value="{!Opp.field2__c}"/>
<apex:outputField value="{!Opp.field3__c}"/>
<apex:outputField value="{!Opp.field4__c}"/>
</apex:pageBlockSection>
I want to have a command button inside the blockSection. Can we have something like a colspan on table to merge the first line to a single column to hold the command button?
Thanks
Prady
pageBlockSection renders as a table inside a div, so once you are "inside" you can just piggyback on that schema (at least until they change how they render sections). You need two columns per section column (in your case 2x2=>4). Use the following
<apex:pageBlockSection collapsible="false" columns="2" >
<tr>
<td colspan="4">
<apex:commandButton ...>
</td>
</tr>
<apex:inputField value="{!Opp.field1__c}"/>
<apex:inputField value="{!Opp.field2__c}"/>
<apex:outputField value="{!Opp.field3__c}"/>
<apex:outputField value="{!Opp.field4__c}"/>
</apex:pageBlockSection>
Related
I wanted to know if it was possible to set an ID that increments in the section. I know that we can set an id, as it's a valid atribute; however, I would like to know how i can set an id that increments (or references a variable that increments).
Can I define a variable (apex:variable) or something else in the vf page that can then be incrememnted via a loop (apex:repeat)?
eg: <apex:variable var="i" value="{!0}"/>
Then in my code I would have: <apex:pageBlock id="'RandomText-'+{!i}">
and in the apex:repeat would have: <apex:variable var="i" value="{!i+1}"/> which would increment the variable.
Would this work?
Example of code:
//DEFINE VARIABLE:
<apex:variable var="i" value="{!0}"/>
<apex:pageBlock>
<apex:pageMessages />
<table id="contacts">
<thead>
//Create table headers
</thead>
<tbody>
<apex:repeat value="{!selected}" var="c">
<apex:pageBlock title="Edit" id="'Randomtext-'+{!i}" mode="edit">
//Iterate through the selected records
<apex:variable var="i" value="{!i+1}"/>
</apex:pageBlock>
</apex:repeat>
</tbody>
</table>
</apex:form>
</apex:page>
The above code should work. I am also doing the same thing increasing the variable value by +1 in page block table. Please see the below code for your reference.
<apex:variable var="schIndex" value="{!0}" />
<apex:pageBlockTable value="{!schedules}" var="sch" title="Existing Schedules">
<apex:column>
<apex:commandLink value="Edit" action="{!editSchedule}" rerender="scheduleSection">
<apex:param name="selectedScheduleId" value="{!schIndex}" />
</apex:commandLink>
<apex:variable var="schIndex" value="{!(schIndex+1)}" />
</apex:column>
<apex:column value="{!name}"/>
</apex:pageBlockTable>
I have a custom Cases apex page where I use a apex:pageBlockTable to display my list of Cases. Here is the code for it:
<apex:page standardController="Case" recordSetVar="Case" sidebar="true" showHeader="true">
<apex:form >
<apex:pageBlock title="Cases">
<apex:outputLabel value="View:"/>
<apex:selectList value="{!filterId}" size="1">
<apex:actionSupport event="onchange" rerender="cases_table"/>
<apex:selectOptions value="{!listviewoptions}"/>
</apex:selectList>
<apex:pageBlock >
<apex:pageBlockButtons >
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!case}" var="c" rows="50" id="cases_table" >
<apex:column >
<a target="_parent" href="{!URLFOR($Action.Case.View, c.id)}">{!c.CaseNumber}</a>
<apex:facet name="header">Case Number</apex:facet>
</apex:column>
<apex:column value="{!c.ContactId}" />
<apex:column value="{!c.Subject}" />
<apex:column value="{!c.Status}" />
<apex:column value="{!c.Priority}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
<base target="_parent"/>
</apex:page>
I would like to get a button inside my apex:pageBlockButtons like in the default Cases page. When the user clicks the button, I would like it to take the user to the new Cases page. I tried this:
<apex:commandButton action="{!new}" value="New"/>
but that gave me an error. How do I make a button that will take me to the new Cases page?
Try this:
<apex:commandButton onclick="window.location.href='{!URLFOR($Action.Case.NewCase)}'" value="New" immediate="true" rerender="blank"/>
Important to note that the rerender tag is needed otherwise the page will do a postback. By using a dummy rerender tag the redirect will work. Immediate is there to avoid running any validation rules on click.
I have a custom Cases apex page where I use a apex:pageBlockTable to display my list of Cases. Here is the code for it(custom object):
<apex:commandButton action="{!URLFOR($Action.Your_Custom_Object__c.New)}" ...>
I have a apex:listView for my Cases:
<apex:ListViews type="Case">
</apex:ListViews>
When I display this page, I get the columns Action, Case Number, Contact Name, Subject, Status, Priority, Date/Time Opened, and Case Owner Alias.
How would I customize which columns show up and what order the columns are in?
Thanks.
This is what I ended up doing:
<apex:page standardController="Case" recordSetVar="Case" sidebar="true" showHeader="true">
<apex:form >
<apex:pageBlock title="Cases">
<apex:outputLabel value="View:"/>
<apex:selectList value="{!filterId}" size="1">
<apex:actionSupport event="onchange" rerender="cases_table"/>
<apex:selectOptions value="{!listviewoptions}"/>
</apex:selectList>
<apex:pageBlock >
<apex:pageBlockButtons >
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!case}" var="c" rows="50" id="cases_table" >
<apex:column >
<a target="_parent" href="{!URLFOR($Action.Case.View, c.id)}">{!c.CaseNumber}</a>
<apex:facet name="header">Case Number</apex:facet>
</apex:column>
<apex:column value="{!c.ContactId}" />
<apex:column value="{!c.Subject}" />
<apex:column value="{!c.Status}" />
<apex:column value="{!c.Priority}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
<base target="_parent"/>
</apex:page>
Apex List Views, similar to standard list views, contain a picklist at the top followed by an Edit button and a Create New View button. You can modify the view by clicking on the Edit button. There is no way, that I am aware of, to modify the columns programmatically. If you need more control, you could use another tag, such as <apex:pageblocktable>, as JCD mentioned in the question comments.
I have a VF page where i am using a apex:pageblocktable to display bunch of records.
One of the columns is a picklist and i need to display/not display fields according to selection on the picklist.
<apex:pageBlockTable value="{!showRecord}" var="item">
<apex:column headerValue="Delivery">
<apex:inputField value="{!item.delivery__c}"/>
</apex:column>
<apex:column headerValue="Roadway">
<apex:inputField value="{!item.road__c}"/>
</apex:column>
<apex:column headerValue="Rail">
<apex:inputField value="{!item.rail__c}"/>
</apex:column>
</apex:pageBlockTable>
in the above code delivery_c is picklist with values roadways and railways. if the user selects roadways then i need to display road--c and if user selects railways then i need to display rail_c
How can i go about doing that?
Thanks
One way to do this would be to use partial-page refreshes in Visualforce.
Put both fields in the same column and use the "rendered" attribute to dynamically show/hide the field using an if-statement. Then you set up an AJAX onchange event handler for the delivery__c field using the actionSupport tag. This will basically listen for that field to change then refresh the table on the page. Each time this is refreshed, your if statements will be re-evaluated and result in showing one of the two fields in that column.
I didn't get a chance to try this but I think it should work.
<apex:pageBlockTable id="mytable" value="{!showRecord}" var="item">
<apex:column headerValue="Delivery">
<apex:actionRegion>
<apex:inputField value="{!item.delivery__c}">
<apex:actionSupport event="onchange" reRender="mytable">
</apex:inputField>
</apex:actionRegion>
</apex:column>
<apex:column headerValue="Delivery Type">
<apex:inputField rendered="{!item.delivery__c='Road'}" value="{!item.road__c}"/>
<apex:inputField rendered="{!item.delivery__c='Rail'}" value="{!item.rail__c}"/>
</apex:column>
</apex:pageBlockTable>
I have created a search query which returns the records in a table. I have used command in the records returned so that i can edit them and save them in the table only. But after changing the records in the table and clicking on the SAVE button, I am not able to update the the records in the table. How can I use 'rerender' to show the updated data? The page code and controller action I'm using are below:
<!-- Page -->
<apex:pageBlock id="pb1">
<apex:outputPanel id="pan">
<apex:pageBlockTable value="{!l1}" var="k" rendered="{!flag}" id="pb">
<apex:column value="{!k.First_Name__c}"/>
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
<apex:column value="{!k.Last_Name__c}"/>
<apex:inlineEditSupport event="ondblclick" showOnEdit="save"/>
<apex:column value="{!k.E_mail__c}"/>
<apex:inlineEditSupport event="ondblclick" showOnEdit="save"/>
<apex:column value="{!k.Employee_ID__c}"/>
<apex:commandButton action="{!save}" id="saveButton" value="Save" />
</apex:pageBlockTable>
</apex:outputPanel>
<apex:commandButton action="{!edit}" id="editButton" value="Edit"/>
<apex:commandButton action="{!save}" id="saveButton" value="Save"/>
<apex:actionSupport event="onclick" rerender="pan" status="refreshstatus"/>
<apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
<apex:actionStatus id="refreshstatus" startstyle="color:green;" startText="Saving....">
</apex:actionStatus>
</apex:pageBlock>
// controller action
public pagereference save(){update l1;return null;}}
Posting some of your code would go a long way here, but the long and the short of it is this:
<!-- put your table in a panel with an ID -->
<apex:outputPanel id="thePanel:>
<!-- put your table here -->
</apex:outputPanel>
<!-- specify the panel's ID as the rerender target for the action -->
<apex:commandButton value="Save" action="{!TheSaveAction}" rerender="thePanel"/>
And then make sure your controller returns a Pagereference with a value of null:
public Pagereference TheSaveAction()
{
// save
return null;
}
If you're still struggling after doing this, put in the page code (or the relevant parts) so I can see what's going on.