primefaces dataTable:如何复制粘贴行

时间:2015-09-26 06:08:02

标签: primefaces datatable copy-paste

我使用primefaces, 我的桌子有超过75列, 当我想复制行并将其粘贴到同一个表中时(当然更改PK后)怎么办

3 个答案:

答案 0 :(得分:0)

您无法开箱即用。我唯一能想到的就是创建一个上下文菜单和/或拦截ctrl-v / c键并调用一些所有为您完成此操作的支持bean方法。但那将是为你创造一个复杂的解决方案。

答案 1 :(得分:0)

您可以使用<p:hotkey>(捕获您的复制和粘贴)以及selectionMode

<p:dataTable>属性

你可以尝试:

<h:form>
   <p:hotkey bind="ctrl+c" actionListener="#{Bean.copy}"/>
   <p:hotkey bind="ctrl+s" actionListener="#{Bean.paste}"/>
   <p:dataTable id="dceTable" value="#{Bean.list}"
                var="row" selection="#{Bean.selection}"
                rowKey="#{row.seqNo}" >
      <p:column selectionMode="multiple" style="width:30px;text-align:center" />
      ... insert your columns here
   </dataTable>
</h:form>

和你的支持bean:

@Named("DCEBean")
@ViewScoped
public class Bean implements Serializable {

public void copy(){
// to copying codes like change PK
}

public void paste(){
// insert in your copied rows
}

}

答案 2 :(得分:-1)

感谢所有答案 但我有一点解决方案:

在&#34; list.xhtml&#34;文件并在上下文菜单面板中添加以下行:

<p:menuitem value="Copy" onclick="document.getElementById('CustomerListForm:copyButton').click();" icon="ui-icon-copy"/>

在文件末尾与其他buttom添加行:

<p:commandButton id="copyButton"   style="visibility: hidden; icon="ui-icon-copy"   value="Copy" update=":CustomerCreateForm" oncomplete="PF('CustomerCreateDialog').show()"/>

了解更多click here