编辑后的 ​​SlickGrid onCellChange 如示例 7 所示

发布于 2024-10-18 05:55:49 字数 660 浏览 1 评论 0原文

如果我将以下代码添加到 SlickGrid 示例 7:

grid.onCellChange.subscribe(function(e,args) 
{
  alert("here");
});

如果我更新文本字段“标题”,则会出现警报。当我更新“优先级”字段时,它不会出现,该字段用于演示单击以切换值。使用此代码捕获点击。

    grid.onClick.subscribe(function(e) {
       var cell = grid.getCellFromEvent(e);
       if (columns[cell.cell].id == "priority") {
          var states = { "Low": "Medium", "Medium": "High", "High": "Low" };
          data[cell.row].priority = states[data[cell.row].priority];
          grid.updateRow(cell.row);
          e.stopPropagation();
       }
    });

问题: 当“优先级”值更改时如何触发 onCellChange?

感谢任何可以提供帮助的人。 约翰.

If I add the following code to SlickGrid example 7:

grid.onCellChange.subscribe(function(e,args) 
{
  alert("here");
});

The alert appears if I update the text field, 'Title'. It does not when I update the 'Priority' field, which is being used to demonstrate click to toggle values. Clicks are captured with this code.

    grid.onClick.subscribe(function(e) {
       var cell = grid.getCellFromEvent(e);
       if (columns[cell.cell].id == "priority") {
          var states = { "Low": "Medium", "Medium": "High", "High": "Low" };
          data[cell.row].priority = states[data[cell.row].priority];
          grid.updateRow(cell.row);
          e.stopPropagation();
       }
    });

Question:
How do I trigger onCellChange when the 'Priority' value changes?

Thank you to anyone who can help.
John.

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

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

发布评论

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

评论(2

清醇 2024-10-25 05:55:49

对我来说非常有意义。
仅当操作在网格内启动时,网格才会引发该事件。
在第二个示例中,您通过拦截特定的单击事件直接对数据源进行更改。

Makes perfect sense to me.
The event is raised by the grid only if the action was initiated within the grid.
In your second example, you are making the change yourself directly against the data source by intercepting specific click events.

伊面 2024-10-25 05:55:49

仅将 JQuery 与 $(#priority).change 选择器一起使用怎么样?

因此,它的外观如下(或类似的内容):

$("#priority").change(function(e) {
    var cell = grid.getCellFromEvent(e);
    var states = { "Low": "Medium", "Medium": "High", "High": "Low" };
    data[cell.row].priority = states[data[cell.row].priority];
    grid.updateRow(cell.row);
    e.stopPropagation();
    });

您可能希望将其更改为使用类而不是 id,因为每个 DOM id 应该在每个页面上保持唯一。

How about just using JQuery with the $(#priority).change selector?

So here is how it would look (or something similar):

$("#priority").change(function(e) {
    var cell = grid.getCellFromEvent(e);
    var states = { "Low": "Medium", "Medium": "High", "High": "Low" };
    data[cell.row].priority = states[data[cell.row].priority];
    grid.updateRow(cell.row);
    e.stopPropagation();
    });

You probably want to change it to use a class instead of an id though, as each DOM id is supposed to remain unique per page.

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