简体   繁体   English

Primefaces LazyLoading表默认选择第一行

[英]Primefaces LazyLoading Table Select First Row by Default

Need Help on the proper way of selecting the first row of a primefaces datatable when the page is refreshed, load, sorted, paged 在刷新,加载,排序和分页页面时,如何选择素数表第一行的正确方法需要帮助

    <p:dataTable id="clientTable" widgetVar="clientTableVar"
                var="client"
                value="#{maintenanceAccountController.clientLazyDataModel}"
                paginator="true" rows="10"
                paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink}  {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}"
                rowsPerPageTemplate="5,10,20" paginatorPosition="bottom"
                pageLinks="5" lazy="true" sortBy="#{client.cclnCode}"
                sortOrder="descending"
                selection="#{maintenanceAccountController.selectedClient}"
                selectionMode="single" filterDelay="500">

                <p:column id="cclnCodeColumn" headerText="Client Code"
                    sortBy="#{client.cclnCode}" filterBy="#{client.cclnCode}"
                    filterMaxLength="10">
                    <h:outputText value="#{client.cclnCode}" />

                    <f:event listener="#{maintenanceAccountController.saveAccount}"
                        type="preRenderView"></f:event>
                </p:column>

                <p:column id="cclnNamenColumn" headerText="Client Name"
                    sortBy="#{client.cclnName}" filterBy="#{client.cclnName}"
                    filterMaxLength="50">
                    <h:outputText value="#{client.cclnName}" />
                </p:column>

            </p:dataTable>

I currently solve this by using this snippet in my managed bean it works that it actually selects and highlight the row. 我目前通过在托管bean中使用此代码段来解决此问题,该代码段实际上可以选择并突出显示该行。

It works because selected client is null when the page is refreshed, while paging, sorting, and filtering automatically sets the selected client to null. 之所以起作用,是因为刷新页面时选定的客户端为空,而分页,排序和筛选会自动将选定的客户端设置为空。 So when the table tries to find the selected client the if logic is executed and I can select the first row of the table. 因此,当表尝试查找选定的客户端时,是否执行了逻辑,因此我可以选择表的第一行。

But I just made my getter a setter and the selected row does not trigger the row selected event (Will ask that problem in a different question). 但是我只是将我的getter设置为setter,并且所选行不会触发该行selected事件(将在另一个问题中询问该问题)。

    public MaintenanceAccountClient getSelectedClient()
{
    if (selectedClient == null)
    {
        int count = clientLazyDataModel.getRowCount();
        int index = clientLazyDataModel.getRowIndex();

        if (index < 0 && count > 0)
        {
            clientLazyDataModel.setRowIndex(0);
            selectedClient = clientLazyDataModel.getRowData();
        }
    }

    return selectedClient;
}

Please note that I am using a LazyDataModel so the client list are only loaded at the RenderPhase if I am not mistaken. 请注意,我使用的是LazyDataModel,因此如果我没有记错的话,客户端列表只会在RenderPhase加载。

I could really use some help. 我真的可以使用一些帮助。 Sample code will really be appreciated. 示例代码将不胜感激。


PrimeFaces 3.5 JSF 2.1 PrimeFaces 3.5 JSF 2.1

i face same issue too. 我也面临同样的问题。 I have to select first row on each page select. 我必须在每个选择的页面上选择第一行。 My solution was simple 我的解决方案很简单

  <p:ajax event="rowSelect" listener="#{protoCnt.setAdditionDetail()}" update=":rightTabForm"/> <p:ajax event="page" oncomplete="myTblWidget.selectRow(0);"/> 

i have two events so on page select event="page" invokes due to myTblWidget.selectRow(0); 我有两个事件,因此由于myTblWidget.selectRow(0);而在页面选择事件=“页面”上调用 rowSelect listener calls setAdditionDetail() rowSelect侦听器调用setAdditionDetail()

    public void setAdditionDetail() {   
    if (selected== null) {
        selected= myLazyModelList.get(0);
    } 
}

so it selects row on bean and client side 因此它选择了bean和客户端上的行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM