在 flex 中,有没有办法在 DataGrid 中捕获并可选地取消行选择事件? [英] In flex, is there a way to capture and optionally cancel a row selection event in a DataGrid?
本文介绍了在 flex 中,有没有办法在 DataGrid 中捕获并可选地取消行选择事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这应该是微不足道的,但我似乎无法找到一种方法来做到这一点.
This should be trivial, but I can't seem to figure out a way to do this.
我有一个 DataGrid,我想做的是当用户单击一行以选择它时,检查某个条件,如果满足则阻止该行被选中并保持旧的选择不变.
I have a DataGrid, and what I would like to do, is when a user clicks on a row to select it, check a certain condition, and if it's met prevent the row from getting selected and keep the old selection intact.
谢谢!
推荐答案
我没有测试它,但它应该可以在 GridSelectionEvent.SELECTION_CHANGING 事件上使用 event.preventDefault() 和/或 event.stopImmediatePropagation() 工作.
I didn't test it, but it should work using event.preventDefault() and/or event.stopImmediatePropagation() on the GridSelectionEvent.SELECTION_CHANGING event.
//stupid function but used for example purpose
private function addListener():void
{
dataGrid.addEventListener(GridSelectionEvent.SELECTION_CHANGING, onSelectionChanging)
}
private function onSelectionChanging(event:GridSelectionEvent):void
{
if(!canRowBeSelected(event.selectionChange.rowIndex))
{
event.stopImmediatePropagation();
event.preventDefault();
}
}
private function canRowBeSelected(index:int):Boolean
{
//add logic
return false;
}
这篇关于在 flex 中,有没有办法在 DataGrid 中捕获并可选地取消行选择事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文