ExtJS - 将外部参数传递给Grid渲染器

时间:2010-11-29 07:59:11

标签: parameters extjs grid renderer

有没有办法将外部参数传递给Grid渲染器函数?

例如,考虑..

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 &amp; status = pending

非常感谢任何帮助。感谢

1 个答案:

答案 0 :(得分:2)

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 }
            ]
        }
    });
}