Extjs4 中的 setRenderer() 方法

发布于 2024-11-09 15:28:34 字数 307 浏览 0 评论 0原文

Extjs 3.3.1 有方法 setRenderer() 现在

/**
  * Sets the rendering (formatting) function for a column. 
  */
setRenderer( Number col, Function fn ) : void

我在 ExtJS 4setRenderer 中没有得到任何方法代码>.那么如何在 ExtJS 4 中运行时格式化网格列。

Extjs 3.3.1 have the method setRenderer() as

/**
  * Sets the rendering (formatting) function for a column. 
  */
setRenderer( Number col, Function fn ) : void

Now I don't get any method in ExtJS 4 of setRenderer. So How can I format grid column at runtime in ExtJS 4.

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

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

发布评论

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

评论(3

风铃鹿 2024-11-16 15:28:34

当您创建网格时,您可以在每一列上定义渲染器...

Ext.create('Ext.grid.Panel', {
    title: 'Grid Sample',
    store: Ext.data.StoreManager.lookup('yourStore'),
    columns: [
        {header: 'Product Description',  dataIndex: 'description'},
        {header: 'Cost', dataIndex: 'cost', renderer: nameOfRenderFunction },
    ],
    height: 200,
    width: 400,
    renderTo: Ext.getBody()
});

然后您可以在全局范围内定义您的函数...

function nameOfRenderFunction(v) {
    //do something to v
    return v;
}

When you're creating your grid you can define the renderer on each column...

Ext.create('Ext.grid.Panel', {
    title: 'Grid Sample',
    store: Ext.data.StoreManager.lookup('yourStore'),
    columns: [
        {header: 'Product Description',  dataIndex: 'description'},
        {header: 'Cost', dataIndex: 'cost', renderer: nameOfRenderFunction },
    ],
    height: 200,
    width: 400,
    renderTo: Ext.getBody()
});

And then you can define your function in a global scope...

function nameOfRenderFunction(v) {
    //do something to v
    return v;
}
天冷不及心凉 2024-11-16 15:28:34

我所做的是事后设置渲染器。在我的应用程序启动后,我获得了实例化的组件,并在控制器的 onLaunch() 函数中添加了一个渲染器,如下所示:

    // An example renderer
    var myComponentsRenderer = function( value ){
        return value++;
    };

    // Get the instantiated component
    var myComponent = Ext.ComponentQuery.query( "#myComponent" )[0];

    // Attach the renderer
    Ext.override( myComponent, {
        renderer : myComponentsRenderer,
    });

我喜欢这种方法的原因是因为我能够将渲染器函数放入我的控制器中并将逻辑保留在我的视图之外。它帮助我更好地组织我的代码。

What I did was set the renderer after the fact. After my application launched, I got the instantiated component and added a renderer in my controller's onLaunch() function like this:

    // An example renderer
    var myComponentsRenderer = function( value ){
        return value++;
    };

    // Get the instantiated component
    var myComponent = Ext.ComponentQuery.query( "#myComponent" )[0];

    // Attach the renderer
    Ext.override( myComponent, {
        renderer : myComponentsRenderer,
    });

The reason I like this method is because I am able to put the renderer functions in my controller and keep logic out of my view. It helps me organize my code better.

墨离汐 2024-11-16 15:28:34

看起来在传递 sencha 论坛上的这篇文章

您可以使用网格的重新配置方法< /a> 交换不同的列列表(以及渲染器),但这确实有一个主要缺点,您必须完全重新指定整个列。

你找到更好的方法了吗?我真的不喜欢这样的事实:它迫使您将渲染器放在无法测试且无法以非静态方式访问状态的地方。

然而,在这种情况下,治疗似乎比疾病更糟糕,因为您最终会将非常明确的视图代码从视图中删除。

有时感觉他们并没有真正考虑过这些东西的设计:(

it looks like the the way to do it is mentioned in passing in this post on the sencha forum.

You can use a grid's reconfigure method to swap in a different list of columns (along with renderers) however this does have the major downside that you'll have to totally respecify the columns in their entirety.

Did you find a better way? I really dont like the fact it forces you to put renderers in a place where they can't be tested and can't access state in a none static way.

However it seems the cure is worse than the disease in this case as you'd end up taking what is very definitely view code out of the view.

Sometimes it feels like they didn't really think about the design of these things very much :(

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