9

render()当方法完成其工作并将所有 HTML 元素附加到 DOM时,我需要执行一些操作。如何订阅onRenderEnds事件(没有这样的事件)?我可以在 slickgrid 代码之外编写自己的事件并将其附加到render()方法吗?


有一些事件"onScroll", "onViewportChanged",但它们在render()完成之前发生(在某些情况下)。


更新:我为列编写格式化程序:

formatter: function(row, cell, value, columnDef, dataContext){
    return "<div class='operationList' data-my='" + myData + "'></div>";            
}

当网格渲染(应用我的格式化程序)时,我需要遍历所有".operationList" divs并将它们转换为其他结构(基于data-my属性)。我需要".operationList" divs用事件处理程序替换复杂的结构。

4

2 回答 2

9

为了回答我自己的评论,我想出了以下技巧。它可能不漂亮,但它似乎工作。

将以下行添加到下面的render()方法中renderRows(rendered);

function render() {
    ...
    renderRows(rendered);
    trigger(self.onRenderCompleted, {}); // fire when rendering is done
    ...
}

向公共 API 添加新的事件处理程序:

"onRenderCompleted":            new Slick.Event(),

绑定到代码中的新事件:

grid.onRenderCompleted.subscribe(function() {
    console.log('onRenderCompleted');
});
于 2011-11-04T09:08:26.333 回答
4

基本答案是不要!你提出的是一个非常糟糕的设计,违背了 SlickGrid 的核心原则和架构。

你最终会做很多多余的工作,并否定 SlickGrid 的大部分性能优势。网格将在您滚动时动态创建和删除行 DOM 节点,并根据当时最适合的方式同步或异步执行此操作。如果您必须在单元格中拥有丰富的交互式内容,请使用自定义单元格渲染器并使用其提供的事件(例如 onClick)将所有事件处理委托给网格级别。如果单元格的内容绝对不能使用渲染器创建,请使用异步后渲染 - http://mleibman.github.com/SlickGrid/examples/example10-async-post-render.html。即使这样,网格内容也不应该有任何事件监听器直接注册到 DOM 节点。

To address @magiconair's comment, you really shouldn't render a whole SELECT with all its options and event handlers until a cell switches into edit mode.

于 2011-11-21T20:27:06.020 回答