YUI 列选择

发布于 2024-08-23 03:55:58 字数 380 浏览 4 评论 0原文

我在使用 YUI 的数据表列选择功能时遇到问题。我已经尝试过,

myEndColDataTable.subscribe("theadCellClickEvent", myEndColDataTable.onEventSelectColumn);

myEndColDataTable.subscribe("cellClickEvent", function (oArgs) { this.selectColumn(this.getColumn(oArgs.target));
});

问题是,我以编程方式选择了一个初始列。我可以突出显示另一列,但它不会从最初选择的列中删除选择。

I'm having issues using YUI's DataTable Column Selection Functionality. I've tried,

myEndColDataTable.subscribe("theadCellClickEvent", myEndColDataTable.onEventSelectColumn);

and

myEndColDataTable.subscribe("cellClickEvent", function (oArgs) {
this.selectColumn(this.getColumn(oArgs.target));
});

The issue is, I have an initial column selected programmatically. I can highlight the other column, but it doesn't remove the selection from the initially-selected column.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜味拾荒者 2024-08-30 03:55:58

你是对的——没有快速干净的解决方案。

YUI DataTable 目前(从 2.8 开始)缺少一个 unselectAllColmns 方法来匹配 unselectAllRows(由 onEventSelectRow 调用)。

还值得注意的是,onEventSelectColumn 选择列标题,因此 unselectAllCells 将不起作用。

您可以像这样实现自己的 unselectAllColumns() 函数:

function unselectAllColumns (dataTable) {
        var i, oColumn, oColumnSet = dataTable.getColumnSet();
        for (i=0; i<oColumnSet.keys.length; i++) {
                oColumn = oColumnSet.keys[i];
                if (oColumn.selected) {
                        dataTable.unselectColumn(oColumn);
                }
        }
}

这比使用 getSelectedColumns() 的效率稍高,因为您不需要构建仅包含选定内容的中间数组columns(查看源代码 getSelectedColumns 调用 getColumnSet 并像上面一样遍历数组)。

You are correct - there is no quick clean solution.

YUI DataTable currently (as of 2.8) lacks an unselectAllColmns method to match unselectAllRows (which is called by onEventSelectRow).

It is also worth noting that onEventSelectColumn selects the column header, so unselectAllCells will not work.

You could implement your own unselectAllColumns() function like this:

function unselectAllColumns (dataTable) {
        var i, oColumn, oColumnSet = dataTable.getColumnSet();
        for (i=0; i<oColumnSet.keys.length; i++) {
                oColumn = oColumnSet.keys[i];
                if (oColumn.selected) {
                        dataTable.unselectColumn(oColumn);
                }
        }
}

This will be marginally more efficient than using getSelectedColumns() because you will not need to build an intermediate array of only selected columns (looking at the source getSelectedColumns calls getColumnSet and walks the array just as above).

凝望流年 2024-08-30 03:55:58

我想我可以做到这一点,但它并不优雅。必须有更好的方法。

myEndColDataTable.subscribe("cellClickEvent", function (oArgs) {
    var colUnSelect = myEndColDataTable.getSelectedColumns();
    myEndColDataTable.unselectColumn(colUnSelect[0]);
    myEndColDataTable.selectColumn(myEndColDataTable.getColumn(oArgs.target));  
});

I guess I can do this, but its not elegant. There has to be a better way.

myEndColDataTable.subscribe("cellClickEvent", function (oArgs) {
    var colUnSelect = myEndColDataTable.getSelectedColumns();
    myEndColDataTable.unselectColumn(colUnSelect[0]);
    myEndColDataTable.selectColumn(myEndColDataTable.getColumn(oArgs.target));  
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文