2

我想创建一个数据表,其中每个单元格都是可点击的。我假设我可以用它填充每个单元格,apex:outputlink并且负责处理可点击部分以及为每次点击调用我的控制器。我需要回答的一个大问题是如何将有关实际单击了哪个单元格(即:哪一行和哪一列)的信息传递给我的顶点控制器。

对此的任何帮助都将受到高度赞赏。

4

1 回答 1

2

这很简单。只需定义一个动作函数来捕获数据表中的值:

1)首先定义三个我们将传递给控制器​​的变量:raw-id,cell-value,cell-type

public String clickedRowId { get; set; } 
public String clickedCellValue { get; set; } 
public String clickedCellType { get; set; } 

public PageReference readCellMethod(){
    System.debug('#### clickedRowId: ' + clickedRowId);
    System.debug('#### clickedCellValue: ' + clickedCellValue);
    System.debug('#### clickedCellType: ' + clickedCellType);
    return null;
}

2)其次我们创建一个动作函数,调用我们的顶点方法并向它传递三个变量:

<apex:actionFunction name="readCell" action="{!readCellMethod}">
    <apex:param name="P1" value="" assignTo="{!clickedRowId}"/>
    <apex:param name="P2" value="" assignTo="{!clickedCellValue}"/>
    <apex:param name="P3" value="" assignTo="{!clickedCellType}"/>
</apex:actionFunction>

3)第三,我们创建我们的数据表,其中每个单元格都有 onClick 监听器:

<apex:pageBlockTable value="{!someArray}" var="item">

    <apex:column value="{!item.name}" onclick="readCell('{!item.id}','{!item.name}','name')" />
    <apex:column value="{!item.CustomField1__c}" onclick="readCell('{!item.id}','{!item.CustomField1__c}','custom1')" />
    <apex:column value="{!item.CustomField2__c}" onclick="readCell('{!item.id}','{!item.CustomField2__c}','custom2')" />

</apex:pageBlockTable>

我们可以像访问任何其他 JavaScript 函数一样访问我们的 actionFunction。如果用户单击单元格 - 三个变量将被发送到 actionFunction,然后发送到控制器。

于 2012-08-14T08:36:47.307 回答