1
<apex:pageblockTable value="{!TasklstI}" var="tsk" id="table">
<apex:column rendered="{!if(ownerhide=false,true,false)}" headerValue="Assigned To"> <apex:commandLink value="{!tsk.owner.name}" action="{!editOwner}"  reRender="table"/></apex:column>
<apex:column rendered="{!if(ownerhide=true,true,false)}" headerValue="Assigned To"   > <apex:inputfield value="{!tsk.ownerId}"  /></apex:column>
</apex:pageblocktable>

public void editOwner(){
ownerhide = true;
}

But my requirement is when I click on hyperlink I need to get only 1 field to be editable. But here the entire column is in editable position. Am i missing anything.

I tried rerendering like this also But this is also not working

<apex:pageblockTable value="{!TasklstI}" var="tsk" >
    <apex:column rendered="{!if(ownerhide=false,true,false)}" headerValue="Assigned To"> <apex:commandLink value="{!tsk.owner.name}" action="{!editOwner}"  reRender="table"/></apex:column>
    <apex:column rendered="{!if(ownerhide=true,true,false)}" headerValue="Assigned To"  id="table" > <apex:inputfield value="{!tsk.ownerId}"  /></apex:column>
    </apex:pageblocktable>
3
  • It's likely to refresh your table since you're rendering whole pageblocktable. If your goal is to edit single row then better to use inlineEdit. – Rohit Mourya Apr 21 '17 at 4:29
  • Anywayz i'm having inline edit for this pageblocktable.since its a hyperlink inlineedit isn't working in this case – Eagerin Sf Apr 21 '17 at 4:32
  • It's better to use standard inline editing provided of VF page or built a cusom one using datatable.. Have a look at this standard inline edit – Rohit Mourya Apr 21 '17 at 4:49
0

The original problem is that the operations you've designed work on the entire column, not just a single cell. For example, the Boolean value ownerEdit is just a single value for all rows; there's no way for the code to know which row you meant. From your current design, I'd say the least amount of work would be to use a temporary record instead.

Controller Changes

Instead of having a Boolean value, we'll identify which row we're currently editing with a temporary task.

public Task ownerTask { get; set; }

In your constructor, remember to initialize the variable:

ownerTask = new Task();

We also need a way to edit the record, so we'll add an action method:

// The apex:commandLink populates this value to tell us which task to edit
public transient Id ownerEditId { get; set; }

public void ownerEdit() {
  ownerTask.Id = ownerEditId;
  // One-liner "find task by Id in a List" trick
  ownerTask.OwnerId = new Map<Id, Task>(TasklstI).get(ownerEditId).OwnerId;
}

We also need a way to update the task when we save:

public void saveEdit() {
  if(ownerTask.Id != null && ownerTask.OwnerId != null) {
    // This code assumes we'll save okay. Consider error handling here.
    update ownerTask;

    // Refresh ownership display value
    Task tempTask = [SELECT Owner.Name FROM Task WHERE Id = :ownerTask.Id];
    new Map<Id, Task>(TaskLstI).get(ownerTask.Id).Owner = tempTask.Owner;

    // end edit mode
    ownerTask.Id = null;
  }
}

And finally a cancel option:

public void cancelEdit() {
  ownerTask.Id = null;
}

Page Changes

Setting a rendered attribute at the apex:column level will affect all rows simultaneously. We only want to affect one row at a time, so we need to set the rendered attribute at the apex:commandLink/apex:inputField level.

<apex:pageblockTable value="{!TasklstI}" var="tsk" id="table">
  <apex:column headerValue="Assigned To">
    <apex:commandLink rendered="{!tsk.Id<>tempTask.Id}" value="{!tsk.owner.name}" action="{!ownerEdit}"  reRender="table">
      <apex:param assignTo="{!ownerEditId}" name="" value="{!tsk.Id}" />
    </apex:commandLink>
    <apex:inputfield value="{!ownerTask.ownerId}" rendered="{!tsk.Id=tempTask.Id}" />
  </apex:column>
</apex:pageblocktable>

N.B. I didn't actually model this in my developer org, so there may be a few minor issues, but this should be very close to correct.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.