如何使用liveScroll选择所有Primefaces DataTable [英] How to select all in primefaces dataTable with liveScroll

查看:116
本文介绍了如何使用liveScroll选择所有Primefaces DataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有liveScroll = true和selectionMode = multiple的primefaces v5.3 dataTable。
标头复选框仅选择可见行,当我向下滚动时,新行显示为未选中。
我希望标题复选框选择所有行:可见和不可见。
仅选择可见行是没有意义和无用的。
是否可以解决?

I'm using primefaces v5.3 dataTable with liveScroll="true" and selectionMode="multiple". Header checkbox selects only visible rows and when i scroll down new rows appear non selected. I want header checkbox to select all rows: visible and invisible. Selection of only visible rows is meaningless and useless. Is it possible to fix?

我试图通过处理 toggleSelect,rowSelectCheckbox和rowUnselectCheckbox事件来将所有表数据添加到选择中。它可在后端运行,但在UI行中仍未选择。

I tried to add all table data to selection by processing "toggleSelect, rowSelectCheckbox and rowUnselectCheckbox" events. It works on backend, but in UI rows are unselected anyway.

推荐答案

使用此脚本替换primefaces的原始updateData函数

Use this script to replace the original updateData function of primefaces

PrimeFaces.widget.DataTable.prototype.updateData = (function() {

    var cached_function = PrimeFaces.widget.DataTable.prototype.updateData;
    return function() {
        var reselectAll = (this.selection != undefined && (this.selection[0] === '@all' || this.selection.length === this.getTbody()[0].getElementsByTagName('tr').length);
        var result = cached_function.apply(this, arguments);
        if (reselectAll) {
            this.selectAllRows();
        }
        return result;
    };
})();

将自动选择表中新加载的行(仅在客户端可见的行)

that will automatically select the new loaded rows on the table(only the ones that are visible on the client side)

这篇关于如何使用liveScroll选择所有Primefaces DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆