jqGrid:当我单击网格外部或其他任何地方时如何失去焦点
我目前正在使用内联编辑进行编辑,当我在网格外部单击时,它仍在编辑中。我应该使用什么事件处理程序来使其调用恢复行函数,这样数据实际发送到服务器的唯一方法是用户按 Enter 键。
提前谢谢
i'm currently doing editing using inline editing, and when i click outside the grid, it's still being under edit. what event handlers should i use to make it call the restore row function, such that the only way for data to actually sent to the server is if the user presses enter.
thx in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我不知道你到底是如何触发内联版本的。我使用 jqGrid 的 ondblClickRow 事件,并且还在寻找一种在用户离开输入或选择时恢复行的方法( 编辑)元素。
我发现跟踪最后选定的元素并在每次单击其他元素时检查它很麻烦。因此,我认为更方便的方法是将
restoreRow
触发器附加到input
或select
的blur
事件> 当前正在编辑的元素,如下所示:这样,只要用户离开编辑字段而不按 Enter 键,就会恢复该行。
这种方法对我来说非常有效,希望对其他人也有帮助。
I don't know exactly how you are triggering the inline edition. I use the
ondblClickRow
event of the jqGrid, and was also looking for a way to restore the row when the user left theinput
orselect
(edit) element.I find it cumbersome to keep track of the last selected element, and checking for it on every click on other elements. So, I think a more convenient way is to attach the
restoreRow
trigger to theblur
event of theinput
orselect
element currently being edited, as so:This way, the row is restored whenever the user leaves the edition field without pressing enter.
This approach works great for me, hope it helps someone else too.
由于主要问题是当您在网格外部单击时您希望失去焦点,因此我编写了此函数来在网格没有 has() 单击的元素时取消选择单元格:
Since the main problem is that you want to lose the focus when you click outside the grid, I wrote this function to unselect the cell just when the grid don't has() the clicked element:
无论如何,我已经想出了如何去做。只是想把它留在网上的某个地方可能会很好,因为我浪费了很多时间来弄清楚如何去做。希望它有帮助=)
只需在某处添加这段代码并将适当的部分(例如 FieldName 和 lastSelectRoot 和 #grid)更改为您已经使用的内容即可。
Anyway, i've figured out how to do it already. Just thought might be good to leave it somewhere online as I wasted quite a bit of time figuring out how to do it. Hope it helps =)
Just add this piece of code somewhere and change the appropriate parts, such as FieldName and lastSelectRoot and #grid to what you are already using.
该解决方案对我有用,并且看起来比其他选项更简单。是通用的,不需要任何全局变量。
基于 $(document).on('click') 的解决方案有一个潜在的缺陷。某些组件(例如 select2)不会将单击事件传播到文档,因此如果您的页面上有它并且被单击(这就是我的情况),它将失败。
This solution is working for me and looks simpler than the other options. Is generic and doesn't need any global variable.
Solutions based on $(document).on('click') have a a potential flaw. Some components like select2 don't propagate the click event to the document, so it will fail if you have it on your page and it's clicked (that was my case).
即使我在使用内联编辑时也遇到了同样的问题。我已经找到了解决方法。我仍然不知道这是否是一个正确的解决方案。
当我编辑一行时,
当我想将数据发送到服务器进行更新时,我使用了这种类型的东西,我在第一行中使用以下语句,然后发送数据到服务器。
希望这能让您了解如何解决您的问题。
顺便说一句,我只制作了一行可以随时编辑。
Even I faced the same issue while working with inline editing.I have gone for a workaround.I still dont know yet whether it is a right a solution.
When I was editing a row I used some thing of this sort
when I wanted to send the data to server to update I am using the following the statement in my first line and sending then sending the data to the server.
Hope this gives you an idea how to do solve your problem.
BTW I have made only one row to be editable at any point of time.
我尝试了几种不同的变体。基于 Mauricio Reis 的 代码我自己写的。
如果您想保存行而不是取消编辑,只需放置
即可
Im tryed few different variants. Based on Mauricio Reis's code I wrote my own.
If you wants to save row instead cancel editing just put
instead