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
beener3beener3 

editable table of data

Hi,

I would like to create a table of data but it must be editable (think Excel)

Each row would be an entry in the object.

is this something that can be done in VF?

Thanks
hisrinuhisrinu
I hope the following example will helps you.
Code:
<apex:page controller="contr1" action="{!test}">
<apex:form >
<apex:pageBlock id="pb">
{!From} - {!To} of {!AccList_Size}
<apex:dataTable value="{!Accounts}" columnswidth="50px,50px"  var="a" cellpadding="4" border="1">
<apex:column > <apex:facet name="header"> <b> Account Name </b> </apex:facet> <apex:inputField value="{!a.Name}"/> </apex:column>
<apex:column > <apex:facet name="header"> <b> Account Type </b> </apex:facet> <apex:inputField value="{!a.Type}"/> </apex:column>
<apex:column > <apex:facet name="header"> <b> BillingCity </b> </apex:facet> <apex:inputField value="{!a.BillingCity}"/> </apex:column>
<apex:column > <apex:facet name="header"> <b> BillingState </b> </apex:facet> <apex:inputField value="{!a.BillingState}"/> </apex:column>
<apex:column > <apex:facet name="header"> <b> BillingPostalCode </b> </apex:facet> <apex:inputField value="{!a.BillingPostalCode}"/> </apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 
beener3beener3
Thanks so much. Just what I needed (didn't try it yet).

Please tell me if you know:
can I use this to update fields in a related object?, that is:the SOQL select statement contains fields obtained via a relationship (using the dot notation).

Thanks so much.
dchasmandchasman
As is  common in VF there are a number of ways to accomplish something - instead of using the low level apex:dataTable I would recommend using apex:pageBlockTable and also take advantage of built in behavior of apex:column's headerValue attribute instead of using a ton of apex:facets with hard coded bold elements, leverage $ObjectType to lookup fully localized labels for things, etc...

Code:
<apex:pageBlock>
<apex:pageBlockTable value="{!accounts}" var="a">
<apex:column headerValue="{!$ObjectType.account.fields.name.label}"><apex:inputField value="{!a.Name}"/></apex:column>
<apex:column headerValue="{!$ObjectType.account.fields.type.label}"><apex:inputField value="{!a.Type}"/></apex:column>
<apex:column headerValue="{!$ObjectType.account.fields.billingCity.label}"><apex:inputField value="{!a.BillingCity}"/></apex:column>
<apex:column headerValue="{!$ObjectType.account.fields.billingSTate.label}"><apex:inputField value="{!a.BillingState}"/></apex:column>
<apex:column headerValue="{!$ObjectType.account.fields.billingPostalCode.label}"><apex:inputField value="{!a.BillingPostalCode}"/></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>

 


beenerbeener
Hi,

I've done as you say, and it seems to be working.
Thanks.

Here's a problem though.

If the data entered fails custom validation rule (that is, the rule is triggered and save is not allowed), I would like to prompt these errors to the user in a reasonable manner.

From a look at the Apex documentation regarding error handling, it seems that I cannot tell which row of data failed the validation.
Any ideas on how to do this?

Thanks

Ben