0

基本上我有别人设计的网站,我真的不懂 ExtJS。我想知道是否有人可以帮助我。

基本上我需要做的是将脚本提取的“名称”总量放在“名称”列标题旁边。

我已经尝试过代码中的 .getCount () 和其他各种函数,但似乎没有任何效果。

任何人都可以帮助我吗?

谢谢!

    MNWG.grid.Charities = function(config) {
    config = config || {};
    Ext.applyIf(config,{
        id: 'mnwg-grid-charities'
        ,url: MNWG.connectorURL
        ,baseParams: { action: 'charities/getList' }
        ,fields: ['id','Created','Name','RegNo','Contact','Address','Postcode','Phone','Fax','Website','Email','Info','Notes','Tags',{name: 'FinancialAid',type:'boolean'}]
        ,paging: true
        ,remoteSort: true
        ,anchor: '97%'
        ,autoExpandColumn: 'name'
        ,columns: [{
            header: 'Name'

            ,dataIndex: 'Name'
            ,sortable: true
            ,width: 400
            ,editor: { xtype: 'textfield' }
        },{
            header: 'Contact'
            ,dataIndex: 'Contact'
            ,sortable: false
        },{
            header: 'Post code'
            ,dataIndex: 'Postcode'
            ,sortable: false
        },{
            header: 'Phone'
            ,dataIndex: 'Phone'
            ,sortable: false
            ,renderer: MNWG.renderers.phoneFax
        },{
            header: 'Website'
            ,dataIndex: 'Website'
            ,sortable: false
            ,renderer: MNWG.renderers.websiteLink
         },{
            header: 'Email'
            ,dataIndex: 'Email'
            ,sortable: false
            ,renderer: MNWG.renderers.emailLink
        }]
        ,tbar:[{
            xtype: 'textfield'
            ,id: 'mnwg-charities-search-filter'
            ,emptyText: 'Search...'
            ,listeners: {
                'change': {fn:this.search,scope:this}
                ,'render': {fn: function(cmp) {
                    new Ext.KeyMap(cmp.getEl(), {
                        key: Ext.EventObject.ENTER
                        ,fn: function() {
                            this.fireEvent('change',this);
                            this.blur();
                            return true;
                        }
                        ,scope: cmp
                    });
                },scope:this}
            }
        },{
            xtype: 'tbfill'
        },{
            xtype: 'button'
            ,text: 'Add new Charity'
            ,handler: {
                xtype: 'mnwg-window-createcharity'
                ,blankValues: true
            }
        }]

    });
    MNWG.grid.Charities.superclass.constructor.call(this,config)
};
Ext.extend(MNWG.grid.Charities,MODx.grid.Grid,{
    search: function(tf,nv,ov) {
        var s = this.getStore();
        s.baseParams.query = tf.getValue();
        this.getBottomToolbar().changePage(1);
        this.refresh();
    }
    ,getMenu: function(a,b,c) {
        var items = Array();

        // Check for a web url
        URL = a.menu.record.Website;
        if(URL != '' && URL != '/'){
            items.push({
                text: 'Visit Website'
                ,handler: this.visitWebsite
            });
        };

        // Check for an email address
        Email = a.menu.record.Email;
        if(Email!=''){
            items.push({
                text: 'Send Email'
                ,handler: this.sendEmail
            });
        };

        // Add update / delete buttons
        items.push({
            text: 'Update Details'
            ,handler: this.updateCharity
        },'-',{
            text: 'Remove Charity'
            ,handler: this.removeCharity
        });
        return items;
    }
    ,visitWebsite: function(a,b){
        var url = a.parentMenu.record.Website
        // Make sure URL is preceded by http://
        var patt= /^http/;
        if( ! patt.test(url)){
          url = 'http://'+url;
        };
        window.open(url);
    }
    ,sendEmail: function(a,b){
        var Email = a.parentMenu.record.Email
        window.open('mailto:'+Email);
    }
    ,removeCharity: function() {
        MODx.msg.confirm({
            title: 'Delete Charity'
            ,text: 'Are you sure you want to delete this charity? This cannot be reversed!'
            ,url: this.config.url
            ,params: {
                action: 'charities/remove'
                ,id: this.menu.record.id
            }
            ,listeners: {
                'success': {fn:this.refresh,scope:this}
                ,'failure': {fn: function(){ alert('fail'); },scope:this}
            }
        });
    }
    ,updateCharity: function(btn,e) {
        if (!this.updateCharityWindow) {
            this.updateCharityWindow = MODx.load({
                xtype: 'mnwg-window-updatecharity'
                ,record: this.menu.record
                ,listeners: {
                    'success': {fn:this.refresh,scope:this}
                }
            });
        }
        this.updateCharityWindow.setValues(this.menu.record);
        this.updateCharityWindow.show(e.target);
    }
});
Ext.reg('mnwg-grid-charities',MNWG.grid.Charities);



MNWG.renderers.websiteLink = function(val,a,record){
    // If no URL return blank
    if(val==''){return'';};

    // Make sure URL is preceded by http://
    var patt= /^http/;
    if( ! patt.test(val)){
      val = 'http://'+val;
    };

    // Create link
    return '<a href="'+val+'" target="_blank">Visit Website</a>';
};

MNWG.renderers.emailLink = function(val,a,record){
  // If no email return blank
  if( val=='' ){return '';};
  return '<a href="mailto:'+val+'">Send Email</a>';
};

MNWG.renderers.phoneFax = function(val,a,record){
    var html = '';
    if(record.data.Phone!=''){
        html+= '<img src="http://m.intertrustgroup.com/images/icon_phone.png" style="margin-right:.5em;">'+record.data.Phone+'<br />';
    };
    if(record.data.Fax!=''){    
        html+= '<img src="http://www.sliksvn.com/gfx/icon_fax.gif" style="margin-right:.5em;">'+record.data.Fax;
    };
    return html;    
};
4

1 回答 1

0

您想在从服务器检索数据的存储上侦听datachanged事件。然后在datachanged上获取列标题并更新它。

以下代码片段是一个示例,说明如何通过将侦听器添加到应用于网格的商店来实现此目的。

更新的代码示例

为简单起见更改名称列

{
    header: 'Name'
    ,id: 'mnwg-grid-charities-name'
    ,dataIndex: 'Name'
    ,sortable: true
    ,width: 400
    ,editor: { xtype: 'textfield' }
}

在此行下方添加以下代码 MNWG.grid.Charities.superclass.constructor.call(this,config);

MNWG.grid.Charities.getStore().addListener('datachanged', function(store) {
    Ext.ComponentManager.get('mnwg-grid-charities-name').setText('Name ' + store.count());
});
于 2012-10-05T10:55:29.713 回答