ExtJS - 将外部参数传递到网格渲染器中

发布于 2024-10-05 02:49:42 字数 1040 浏览 8 评论 0原文

有没有办法将外部参数传递到网格渲染器函数中?

例如,考虑到..

function excelRenderer(value, p,record){
  return String.format('<a href="excel.jsp?view=aging&prod_type={0}&value={1}" target="_blank"><img src="images/excel.png" border="0"/></a>',record.data.prod_type,value);
} 

function newtab(status){
//add tab
  tabs.add({ 
  ...
  items: new Ext.grid.GridPanel({
                region:'center',
                frame: true,
                title: 'testing',
                store: new Ext.data.Store({
                    ...
                }),
                columns: [
                {header: "Column 2", dataIndex: 'col2', sortable: true, renderer: excelRenderer},
                {header: "Column 1", dataIndex: 'col1', sortable: true, renderer: excelRenderer}
                ]
            }
}

现在我想将外部参数 status 添加到渲染器中,以便渲染的 URL 看起来像

excel.jsp?view=aging&prod_type=data&value=testing&status=pending

非常感谢任何帮助。谢谢

is there a way to pass external parameter into Grid renderer function?

For example, considering..

function excelRenderer(value, p,record){
  return String.format('<a href="excel.jsp?view=aging&prod_type={0}&value={1}" target="_blank"><img src="images/excel.png" border="0"/></a>',record.data.prod_type,value);
} 

function newtab(status){
//add tab
  tabs.add({ 
  ...
  items: new Ext.grid.GridPanel({
                region:'center',
                frame: true,
                title: 'testing',
                store: new Ext.data.Store({
                    ...
                }),
                columns: [
                {header: "Column 2", dataIndex: 'col2', sortable: true, renderer: excelRenderer},
                {header: "Column 1", dataIndex: 'col1', sortable: true, renderer: excelRenderer}
                ]
            }
}

now I want to add external parameter status into the renderer so that the URL rendered will look like

excel.jsp?view=aging&prod_type=data&value=testing&status=pending

Any help is much appreciated. Thanks

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

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

发布评论

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

评论(1

相守太难 2024-10-12 02:49:42

将渲染器函数定义移至 newTab() 函数体内:

function newtab(status){
    var excelRenderer = function(value, p,record){
        return String.format('<a href="excel.jsp?view=aging&prod_type={0}&value={1}&status={2}" target="_blank"><img src="images/excel.png" border="0"/></a>',record.data.prod_type,value, status);
    } 

    //add tab
    tabs.add({ 
        ...
        items: new Ext.grid.GridPanel({
            region:'center',
            frame: true,
            title: 'testing',
            store: new Ext.data.Store({
                ...
            }),
            columns: [
                {header: "Column 2", dataIndex: 'col2', sortable: true, renderer: excelRenderer},
                {header: "Column 1", dataIndex: 'col1', sortable: true, renderer: excelRenderer}
            ]
        }
    });
}

还有其他一些方法(例如,创建绑定到补充参数 excelRenderer 函数回调) status),但这似乎是最简单的方法。

编辑(使用绑定参数的第二个选项):

var excelRenderer = function(v, m, r, ri, ci, s, status){
    return String.format('<a href="excel.jsp?view=aging&prod_type={0}&value={1}&status={2}" target="_blank"><img src="images/excel.png" border="0"/></a>',r.data.prod_type, v,  status);
} 

function newtab(status){
    var statusExcelRenderer = excelRenderer.createDelegate(null, [ status ], true);

    //add tab
    tabs.add({ 
        ...
        items: new Ext.grid.GridPanel({
            region:'center',
            frame: true,
            title: 'testing',
            store: new Ext.data.Store({
                ...
            }),
            columns: [
                { header: "Column 2", dataIndex: 'col2', sortable: true, renderer: statusExcelRenderer },
                { header: "Column 1", dataIndex: 'col1', sortable: true, renderer: statusExcelRenderer }
            ]
        }
    });
}

Move the renderer function definition inside the newTab() function body:

function newtab(status){
    var excelRenderer = function(value, p,record){
        return String.format('<a href="excel.jsp?view=aging&prod_type={0}&value={1}&status={2}" target="_blank"><img src="images/excel.png" border="0"/></a>',record.data.prod_type,value, status);
    } 

    //add tab
    tabs.add({ 
        ...
        items: new Ext.grid.GridPanel({
            region:'center',
            frame: true,
            title: 'testing',
            store: new Ext.data.Store({
                ...
            }),
            columns: [
                {header: "Column 2", dataIndex: 'col2', sortable: true, renderer: excelRenderer},
                {header: "Column 1", dataIndex: 'col1', sortable: true, renderer: excelRenderer}
            ]
        }
    });
}

There are some other ways (e.g. creating a function callback to excelRenderer that's being bound to a supplemental parameter status), but this seems to be the easiest way.

EDIT (second option using bound parameters):

var excelRenderer = function(v, m, r, ri, ci, s, status){
    return String.format('<a href="excel.jsp?view=aging&prod_type={0}&value={1}&status={2}" target="_blank"><img src="images/excel.png" border="0"/></a>',r.data.prod_type, v,  status);
} 

function newtab(status){
    var statusExcelRenderer = excelRenderer.createDelegate(null, [ status ], true);

    //add tab
    tabs.add({ 
        ...
        items: new Ext.grid.GridPanel({
            region:'center',
            frame: true,
            title: 'testing',
            store: new Ext.data.Store({
                ...
            }),
            columns: [
                { header: "Column 2", dataIndex: 'col2', sortable: true, renderer: statusExcelRenderer },
                { header: "Column 1", dataIndex: 'col1', sortable: true, renderer: statusExcelRenderer }
            ]
        }
    });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文