简体   繁体   English

Tabulator: titleFormatter: "rowSelection" when clicking header select all 复选框

[英]Tabulator: titleFormatter: "rowSelection" when clicking header select all checkbox

When I click on the checkbox to select/deselect all rows in my table the headerClick function doesn't fire (It will fire for everything in the header but the checkbox).当我单击复选框以选择/取消选择表中的所有行时, headerClick function 不会触发(它会触发 header 中的所有内容,但复选框除外)。 This is my column set up for it and I'm just wondering if this is a bug or if there is another way for me to trigger my function of getting all selected rows when I click the select all checkbox.这是我为此设置的专栏,我只是想知道这是否是一个错误,或者是否有另一种方法可以让我在单击 select 全部复选框时触发我的 function 获取所有选定的行。 Thanks!谢谢!

columns: [
    {
        formatter: "rowSelection",
        titleFormatter: "rowSelection",
        hozAlign: "center",
        headerSort: false,
        visible: true,
        width: 40,
        headerClick: (e, column) => {
            console.log(e);
            let table = column.getTable();
            this.selectedRows = table.getSelectedRows();
            this.rowCount = this.selectedRows.length;
        }
    },

wouldnt say its a "bug", but it looks like you have a feature request, defintiely.不会说它是“错误”,但看起来您确实有一个功能请求。 The code for rowSelection has : rowSelection 的代码有:

checkbox.addEventListener("click", function (e) {
    e.stopPropagation();
});

so on it's click, it's not letting anyone else know about it with stopProp().所以在点击它时,它不会通过 stopProp() 让其他人知道它。 And I dont see any code to getHeaderCheckbox() so that you might add your own clickHandler.而且我没有看到 getHeaderCheckbox() 的任何代码,因此您可以添加自己的 clickHandler。

So I would go to to GitHub and lodge a feature request to be able to add your own handlers to this item.所以我会去 GitHub 并提出一个功能请求,以便能够将您自己的处理程序添加到该项目。 Unless he's already done it in 5.0 ?除非他已经在 5.0 中完成了? I haven't looked at it yet...我还没看。。。

in the meantime, you could do your own version of this and not use the "rowSelection" formatter, or you could do a WHOLE lot of work to with getChildElements() to get a handle on the actual DOM element and insert your own handler (that would be LAST resort IMHO)同时,您可以执行自己的版本而不使用“rowSelection”格式化程序,或者您可以使用 getChildElements() 进行大量工作以获取实际 DOM 元素的句柄并插入您自己的处理程序(那将是最后的手段恕我直言)

If you ABSOLUTELY must have it NOW (and I would absolutely NOT advise you doing this !!!) :如果您现在绝对必须拥有它(我绝对不建议您这样做!!!):

Give your column a "field" (say "selector" for example) for easy access and after your "new Tabulator()" ...为您的列提供一个“字段”(例如“选择器”)以便于访问,并在“new Tabulator()”之后...

table.getColumn("selector")._column.titleElement.firstChild.addEventListener("click", function (e) {
    console.log(e);
    e.stopPropagation();
});

I did not say this, I was never here ....我没有说这个,我从来没有在这里......

The issue is you are trying to add functionality that isnt needed.问题是您正在尝试添加不需要的功能。 The rowSelection formatter when used in the titleFormatter option will automatically handle the select/deselect all functionality, there is no need to listen to any click events yourself.titleFormatter选项中使用的rowSelection格式化程序将自动处理选择/取消选择所有功能,无需自己收听任何点击事件。 it will do it all for you.它会为你做这一切。

By adding the additional headerClick handler you are immediately negating the selection, by toggling things a second time通过添加额外的headerClick处理程序,您可以通过第二次切换来立即否定选择

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

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