【问题标题】:How move between row and page in Primefaces Datatable如何在 Primefaces Datatable 中的行和页面之间移动
【发布时间】:2019-06-09 05:30:40
【问题描述】:

我想要一个在数据表中上下行之间移动的代码,带有两个按钮,最后一行转到下一页。

我可以编写在行之间移动的代码,但我无法转到最后一行的下一页。我的代码在这里,它有两个用于在行之间向上和向下的函数(tableWidgetVar 是 datatable widgetvar):

    downRow = function (tableWidgetVar) {
        if (PF(tableWidgetVar).selection.length === 0) {
             PF(tableWidgetVar).selectRow(0);
             return;
        }
        var index = PF(tableWidgetVar).originRowIndex;
        var rows = PF(tableWidgetVar).tbody[0].childElementCount;
        index++;

        PF(tableWidgetVar).unselectAllRows();
        PF(tableWidgetVar).selectRow(index);
        PF(tableWidgetVar).originRowIndex = index;
    },

    upRow = function (tableWidgetVar) {
        var rows = PF(tableWidgetVar).tbody[0].childElementCount;
        var index = PF(tableWidgetVar).originRowIndex;
            index--;
        PF(tableWidgetVar).unselectAllRows();
        PF(tableWidgetVar).selectRow(index);
        PF(tableWidgetVar).originRowIndex = index;
    },

有人知道转到最后一行的下一个数据表页面吗?

【问题讨论】:

    标签: primefaces primefaces-datatable


    【解决方案1】:
    【解决方案2】:

    你需要两个条件,如果你在第一行或者你在页面的最后一行,当你在最后一行时转到下一页,当你在第一行时转到上一页。为此你必须使用PF(tableWidgetVar).paginator。但是当您在第一页或最后一页时,您还有两个附加条件,因为您没有下一页或上一页。像这样编辑您的代码:

    downRow = function (tableWidgetVar) {
        if (PF(tableWidgetVar).selection.length === 0) {
             PF(tableWidgetVar).selectRow(0);
             return;
        }
        var index = PF(tableWidgetVar).originRowIndex;
        var rows = PF(tableWidgetVar).tbody[0].childElementCount;
        index++;
        if (index === rows) {
            if (PF(tableWidgetVar).paginator.getCurrentPage() === PF(tableWidgetVar).paginator.cfg.pageCount - 1) {
                return;
            }else {
                PF(tableWidgetVar).getPaginator().next();
                \\or PF(tableWidgetVar).paginator.setPage(PF(tableWidgetVar).paginator.getCurrentPage() + 1);
                index = 0;
            }
        }
        PF(tableWidgetVar).unselectAllRows();
        PF(tableWidgetVar).selectRow(index);
        PF(tableWidgetVar).originRowIndex = index;
    },
    
    upRow = function (tableWidgetVar) {
    
        var rows = PF(tableWidgetVar).tbody[0].childElementCount;
        var index = PF(tableWidgetVar).originRowIndex;
        if (index === 0) {
            if(PF(tableWidgetVar).paginator.getCurrentPage()=== 0){
                return;
            }else {
                PF(tableWidgetVar).paginator.setPage(PF(tableWidgetVar).paginator.getCurrentPage() - 1);
                    index = rows - 1;
            }
        } else {
            index--;
        }
        PF(tableWidgetVar).unselectAllRows();
        PF(tableWidgetVar).selectRow(index);
        PF(tableWidgetVar).originRowIndex = index;
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多