How to select all in primefaces dataTable with liveScroll

我与影子孤独终老i 提交于 2019-12-24 10:49:20

问题


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?

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.


回答1:


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)



来源:https://stackoverflow.com/questions/41369335/how-to-select-all-in-primefaces-datatable-with-livescroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!