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.
inlineEdit
. – Rohit Mourya Apr 21 '17 at 4:29