+ Start a Discussion

editable table of data


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?

I hope the following example will helps you.
<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>

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.
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...

<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>



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

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?