Flex 4.5 Spark DataGrid - 检测在选择更改处理程序中单击的列

发布于 2024-11-02 21:19:25 字数 288 浏览 3 评论 0原文

我有一个带有 selectionMode="multipleRows" 的 Spark 数据网格。

我的数据网格中有三列。

我不希望当用户的点击落在行的第三列上时发生行选择。

仅当单击前两列之一时才应进行行选择。

我该如何实现这一目标?数据网格有一个 selectionChanging 事件,但处理程序中收到的 GridSelectionEvent 对象似乎没有提供有关发生单击的列的任何信息。

谢谢!

I have a spark datagrid with selectionMode="multipleRows".

I have three columns in the datagrid.

I don't want the row selection to happen when the user's click falls on the third column of a row.

The row selection should happen only when one of the first two columns is clicked.

How do I achieve this? There is a selectionChanging event for the datagrid, but the GridSelectionEvent object received in the handler does not seem to provide any information about the column on which the click happened.

Thanks!

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

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

发布评论

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

评论(2

南城旧梦 2024-11-09 21:19:26

我知道它已经 13 岁了,但今天我遇到了同样的问题,我是这样做的:

protected function dataGrid_itemClickHandler(e:GridSelectionEvent):void             {
            var mouseX:Number = dataGrid.mouseX;
            mouseX += dataGrid.scroller.horizontalScrollBar.value;
            var lastPosX:Number = 0;
            var posX:Number = 0;
            for (var i:int=0; i<dataGrid.columns.length; i++){
                posX += dataGrid.grid.getColumnWidth(i);
                if ((mouseX > lastPosX) && (mouseX< posX)){
                    break;
                }
                lastPosX += dataGrid.grid.getColumnWidth(i);
            }
            //now i is the column index cliqued
            var dc:GridColumn = dataGrid.columns[i];
}

大黑客,但它正在工作

I know it's 13 years old, but I have same issue today, here how I done :

protected function dataGrid_itemClickHandler(e:GridSelectionEvent):void             {
            var mouseX:Number = dataGrid.mouseX;
            mouseX += dataGrid.scroller.horizontalScrollBar.value;
            var lastPosX:Number = 0;
            var posX:Number = 0;
            for (var i:int=0; i<dataGrid.columns.length; i++){
                posX += dataGrid.grid.getColumnWidth(i);
                if ((mouseX > lastPosX) && (mouseX< posX)){
                    break;
                }
                lastPosX += dataGrid.grid.getColumnWidth(i);
            }
            //now i is the column index cliqued
            var dc:GridColumn = dataGrid.columns[i];
}

Big hack but it's working

远山浅 2024-11-09 21:19:25

我自己想出了这个办法。我不确定这是否是 Spark DataGrid 中的错误。下面的内容绝对是一个 hack 并且不干净。

DataGrid.as文件的grid_mouseDownHandler函数中,有一行:

const columnIndex:int = isCellSelection ?事件.columnIndex : -1;

如果 DataGridselectionMode 不是以下任何内容,则此行会导致 columnIndex 设置为 -1 GridSelectionMode.SINGLE_CELLGridSelectionMode.MULTIPLE_CELLS。正如我在原来的问题中提到的,我需要我的数据网格的 selectionModeGridSelectionMode.MULTIPLE_ROWS

我对 DataGrid 进行了子类化并重新实现了 grid_mouseDownHandler (基本上是复制粘贴整个函数)。我仅更改了上面的行,以始终将 columnIndex 分配给 event.columnIndex

(我还必须将 grid_mouseDownHandler 引用的更多函数复制到我的子类,因为这些函数是 protected 或 mx_internal。(toggleSelection,extendSelection , isAnchorSet)

然后,在 selectionChanging 事件处理程序中,我可以执行以下操作:

if( 2 == event.selectionChange.columnIndex )
{
    event.preventDefault();
}

我意识到这不是一个干净的解决方案,但这是我能想到的最好的解决方案。也许有人可以提出更好的解决方案?

I figured this out myself. I am not sure if this is a bug in the spark DataGrid. The following is definitely a hack and not clean.

In the grid_mouseDownHandler function in the DataGrid.as file, there is a line:

const columnIndex:int = isCellSelection ? event.columnIndex : -1;

This line is causing the columnIndex to be set as -1 if the selectionMode of the DataGrid is anything other than GridSelectionMode.SINGLE_CELL or GridSelectionMode.MULTIPLE_CELLS. As I mentioned in the original question, I need my datagrid to have a selectionMode of GridSelectionMode.MULTIPLE_ROWS.

I sub-classed the DataGrid and re-implemented the grid_mouseDownHandler (basically copy-pasted the whole function). I changed only the above line to always assign the columnIndex to event.columnIndex.

(I also had to copy some more functions which were referenced by the grid_mouseDownHandler over to my sub-class because those functions were protected or mx_internal. (toggleSelection, extendSelection, isAnchorSet)

Then, in the selectionChanging event handler, I could just do the following:

if( 2 == event.selectionChange.columnIndex )
{
    event.preventDefault();
}

I realize that this is not a clean solution, but it is the best I could think of. Maybe someone can suggest a better solution?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文