EXTjs 3.4.0使用NAME在网格中呈现ID字段

EXTjs 3.4.0 render a ID field in grid with NAME

本文关键字:ID 字段 网格 使用 NAME EXTjs      更新时间:2023-09-26

我有一个EXTjs网格,它显示数据库中自定义表中的一些字段。。

Reports.grid.Reports = function(config) {
    config = config || {};
    Ext.applyIf(config,{
        id: 'reports-grid-reports'
        ,url: Reports.config.connectorUrl
        ,baseParams: { action: 'mgr/reports/getList' }
        ,save_action: 'mgr/reports/updateFromGrid'
        ,fields: ['id','name','filename','remark','year','resourceID','typeID','visible']

然后:

{
             header: 'Type ID'
            ,dataIndex: 'typeID'
            ,sortable: true
            ,width: 100
         }

我的类型表有typeid和名称。。我的网格显示数字,我如何告诉它在表中显示该id的对应名称?

我还得到了一个组合框,我在更新窗口中使用:

Reports.combo.Types = function(config) {
    config = config || {};
    Ext.applyIf(config,{          
         name: 'typeID'       
        ,hiddenName: 'typeID'
        ,displayField: 'name'
        ,valueField: 'id'
        ,fields: ['name','id']
        ,listWidth: 380       
        ,pageSize: 20
        ,url: Reports.config.connectorUrl
        ,baseParams: {
                action: 'mgr/reports/gettypelist2', 'combo': true
            }           
    });
    Reports.combo.Types.superclass.constructor.call(this,config);
};
Ext.extend(Reports.combo.Types,MODx.combo.ComboBox);
Ext.reg('combo-modx-types',Reports.combo.Types);

使用,displayField:'name'使组合显示名称而不是id。我如何在网格中做同样的事情?

如果我正确理解这个问题,我相信你需要自定义getList处理器,而不是直接在ExtJS中。重写afterIteration()函数。大致如下:

public function afterIteration(array $list) {
    $rows = array();
    foreach ($list as $row){
        // This calls a custom getName() function that gets the name from the other table 
        $row['typeID'] = $this->getName($row['id']); 
        $rows[] = $row;
    }
    return $rows;
}

也许你的getName()函数可以是这样的:

private function getName($id) {
    $otherTable = $this->modx->getObject('TABLE_ALIAS_HERE', array('internalKey' => $id));
    $name = $otherTable->get('name');
    return $name;
}