简体   繁体   English

启用排序时,React-Virtualized取消单击事件

[英]React-Virtualized cancel click event when sort enabled

I'm creating a table where the columns are resizable like the demo on the react-virtualized GitHub page using react-draggable: https://codesandbox.io/s/j30k46l7xw 我正在创建一个表,其中的列可以像使用react-draggable的react-virtualized GitHub页面上的演示一样调整大小: https//codesandbox.io/s/j30k46l7xw

However, I also want the table to support sorting. 但是,我也希望该表支持排序。

When I add the sort prop on the table, the sort function is called everytime a column is resized and the mouse is still inside the header column. 当我在表上添加sort道具时,每当调整列的大小并且鼠标仍在标题列中时,都会调用sort函数。

Check out the console log here where I have added the sort prop to the above demo: https://codesandbox.io/s/n32x4ry1ym 在这里查看控制台日志,在该日志中我已将sort道具添加到上述演示中: https : //codesandbox.io/s/n32x4ry1ym

Is there any way to stop the sort function from being called? 有什么方法可以阻止sort函数被调用? I've tried adding event.stopPropagation() to the onStart , onDrag and onStop in react-draggable. 我试过将event.stopPropagation()添加到react-draggable的onStartonDragonStop中。 I also found out that the react-draggable onStop is called before react-virtualized sort . 我还发现,react-draggable onStop在react-virtualized sort之前被调用。

Any ideas? 有任何想法吗?

Just a quick parse through draggable's source code made me believe that an onClick listener which stops event propagation on should work. 快速浏览一下Draggable的源代码,使我相信停止事件传播的onClick侦听器应该可以工作。 But for some reason it didn't. 但是由于某种原因,它没有。 Another quick way to do this would be to wrap draggable in a div which stops the click event propagation. 另一种快速的方法是将可拖动对象包装在div中,以停止点击事件的传播。

https://codesandbox.io/s/ymov0zmwjx check here, just added a wrapper around your draggable component. https://codesandbox.io/s/ymov0zmwjx在此处检查,只是在可拖动组件周围添加了包装器。 onStart, onStop, onDrag wouldn't work here because internally these are using mouse events while the virtualized table is using click a event. onStart,onStop,onDrag在这里不起作用,因为在内部,这些控件使用鼠标事件,而虚拟化表使用的是单击事件。

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

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