Slickgrid - 一键复选框?
当我在 Slickgrid 中创建复选框列(通过使用格式化程序/编辑器)时,我注意到需要单击两次才能与其交互(一次单击聚焦单元格,一次单击与复选框交互)。 (这非常有道理)
但是,我注意到我可以通过一键单击与复选框选择器插件(用于选择多行)进行交互。有什么方法可以让我的所有复选框都以这种方式运行吗?
When I create a checkbox column (through use of formatters/editors) in Slickgrid, I've noticed that it takes two clicks to interact with it (one to focus the cell, and one to interact with the checkbox). (Which makes perfect sense)
However, I've noticed that I am able to interact with the checkbox selectors plugin (for selecting multiple rows) with one click. Is there any way I can make ALL of my checkboxes behave this way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对于更多的读者,我通过修改单击事件上的网格数据本身解决了这个问题。将布尔值设置为相反,然后格式化程序将显示单击或未单击的复选框。
希望有帮助。
For futher readers I solved this problem by modifing the grid data itself on click event. Setting boolean value to opposite and then the formatter will display clicked or unclicked checkbox.
Hope it helps.
我的做法非常简单。
第一步是您必须禁用复选框的编辑器处理程序。
在我的项目中它看起来像这样。我有一个 slickgridhelper.js 来注册插件并使用它们。
下一步是在您正在开发的自定义 js 页面中注册 onClick 事件处理程序。下一步
现在,只需单击一次即可更改复选框的值并保留它。
The way I have done it is pretty straight forward.
First step is you have to disable the editor handler for your checkbox.
In my project it looks something like this. I have a slickgridhelper.js to register plugins and work with them.
Next step is to register an onClick event handler in your custom js page which you are developing.
Now a single click is suffice to change the value of your checkbox and persist it.
为“onClick”事件注册一个处理程序,并对其中的数据进行更改。
请参阅http://mleibman.github.com/SlickGrid/examples/example7-events。 html
Register a handler for the "onClick" event and make the changes to the data there.
See http://mleibman.github.com/SlickGrid/examples/example7-events.html
我发现解决这个问题的唯一方法是编辑
slick.checkboxselectcolumn.js
插件。我喜欢订阅方法,但它没有为我附加任何单选按钮的侦听器。所以我所做的就是编辑函数handleClick(e, args) & handleHeaderClick(e, args)。
我添加了函数调用,并且在我的 js 文件中我只是用它做了我想做的事情。
代码
pastebin.com/22snHdrw
在评论中搜索我的用户名
The only way I found solving it is by editing the
slick.checkboxselectcolumn.js
plugin. I liked the subscribe method, but it haven't attached to me any listener to the radio buttons.So what I did is to edit the functions handleClick(e, args) & handleHeaderClick(e, args).
I added function calls, and in my js file I just did what I wanted with it.
Code
pastebin.com/22snHdrw
Search for my username in the comments
我使用
onBeforeEditCell
事件为我的布尔字段“can_transmit”实现此目的基本上捕获编辑单元格,单击所需的列,自己进行更改,然后返回 false停止单元格编辑事件。
这对我有用。但是,如果您使用 DataView 功能(例如过滤),则需要执行额外的工作来通过此更改更新数据视图。 我还没想出如何做到这一点......
I used the
onBeforeEditCell
event to achieve this for my boolean field 'can_transmit'Basically capture an edit cell click on the column you want, make the change yourself, then return false to stop the cell edit event.
This works for me. However, if you're using the DataView feature (e.g. filtering), there's additional work to update the dataview with this change. I haven't figured out how to do that yet...
我设法让单击编辑器与 DataView 一起工作,相当黑客。
通过调用我的 CheckBoxCellEditor 函数,并调用 Slick.GlobalEditorLock.commitCurrentEdit();, 当单击 CheckBoxCellEditor 创建的复选框时(通过 setTimeout)。
问题是,单击 CheckBoxCellFormatter 复选框,然后该事件会生成 CheckBoxCellEditor 代码,该代码会用新的复选框替换该复选框。如果您只是在该选择器上调用 jquery 的 .click() ,您将再次触发 CheckBoxCellEditor 事件,因为 slickgrid 尚未取消绑定最初让您到达那里的处理程序。 setTimeout 在删除该处理程序后触发单击(我担心计时问题,但我无法在任何浏览器中生成任何问题)。
抱歉,我无法提供任何示例代码,我拥有的代码是特定于实现的,可用作通用解决方案。
I managed to get a single click editor working rather hackishly with DataView by calling
in my CheckBoxCellEditor function, and calling Slick.GlobalEditorLock.commitCurrentEdit(); when the CheckBoxCellEditor created checkbox is clicked (by that setTimeout).
The problem is that the CheckBoxCellFormatter checkbox is clicked, then that event spawns the CheckBoxCellEditor code, which replaces the checkbox with a new one. If you simply call jquery's .click() on that selector, you'll fire the CheckBoxCellEditor event again due because slickgrid hasn't unbound the handler that got you there in the first place. The setTimeout fires the click after that handler is removed (I was worried about timing issues, but I was unable to produce any in any browser).
Sorry I couldn't provide any example code, the code I have is to implementation specific to be useful as a general solution.