ExtJS4 获取表格汉字表头

Ext.create('Ext.data.Store', {
    storeId:'simpsonsStore',
    fields:['name', 'email', 'phone'],
    data:{'items':[
        { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "phone":"555-111-1224"  },
        { 'name': 'Bart',  "email":"bart@simpsons.com",  "phone":"555-222-1234" },
        { 'name': 'Homer', "email":"home@simpsons.com",  "phone":"555-222-1244"  },
        { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254"  }
    ]},
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            root: 'items'
        }
    }
});
              
 function getColumnText(columns, attr){
    var text = '';
    Ext.Array.each(grid.columns, function(column){
         if(column.dataIndex == attr){
             text = column.text;
             return false;
         }
    });
    return text;
 }
              
 var grid = Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
            store: Ext.data.StoreManager.lookup('simpsonsStore'),
            columns: [
                { text: '姓名',  dataIndex: 'name' },
                { text: '邮件', dataIndex: 'email', flex: 1 },
                { text: '电话', dataIndex: 'phone' }
            ],
            height: 600,
            width: 800,
            selModel: {
                xtype: 'rowmodel',
                mode: 'MULTI'
            },
            tbar:[{
                xtype: 'button',
                text: '获取选择',
                handler:function(){
                    //console.log(grid.columns);
                    var records = grid.getSelectionModel().getSelection();
                    //console.log(records);
                    Ext.Array.each(records, function(record){
                        //console.log(record.data);
                        for(var attr in record.data){
                            console.log(getColumnText(grid.columns, attr) + ' => ' + record.data[attr]);
                        }
                                     
                    });
                                 
                    Ext.Array.each(grid.columns, function(record){
                        //console.log(record);
                    });
                }
            }]
});

                Ext.create('Ext.data.Store', {
                    storeId:'simpsonsStore',
                    fields:['name', 'email', 'phone'],
                    data:{'items':[
                        { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "phone":"555-111-1224" },
                        { 'name': 'Bart',  "email":"bart@simpsons.com",  "phone":"555-222-1234" },
                        { 'name': 'Homer', "email":"home@simpsons.com",  "phone":"555-222-1244" },
                        { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254" }
                    ]},
                    proxy: {
                        type: 'memory',
                        reader: {
                            type: 'json',
                            root: 'items'
                        }
                    }
                });
                    
                 function getColumnText(columns, attr){
                    var text = '';
                    Ext.Array.each(grid.columns, function(column){
                         if(column.dataIndex == attr){
                             text = column.text;
                             return false;
                         }
                    });
                    return text;
                 }
                    
                 var colsConfig = {
                     colsObj : { name: '姓名', email: '邮件', phone : '电话'},
                     cols : [{ text: '姓名', dataIndex: 'name' },{ text: '邮件', dataIndex: 'email' },{ text: '电话', dataIndex: 'phone' }]
                };
                    
                 var grid = Ext.create('Ext.grid.Panel', {
                    title: 'Simpsons',
                            store: Ext.data.StoreManager.lookup('simpsonsStore'),
//                            columns: [
//                                { text: '姓名',  dataIndex: 'name' },
//                                { text: '邮件', dataIndex: 'email', flex: 1 },
//                                { text: '电话', dataIndex: 'phone' }
//                            ],
                            columns: colsConfig.cols,
                            height: 600,
                            width: 800,
                            selModel: {
                                xtype: 'rowmodel',
                                mode: 'MULTI'
                            },
                            tbar:[{
                                xtype: 'button',
                                text: '获取选择',
                                handler:function(){
                                    //console.log(grid.columns);
                                    var records = grid.getSelectionModel().getSelection();
                                    //console.log(records);
                                    Ext.Array.each(records, function(record){
                                        //console.log(record.data);
                                        for(var attr in record.data){
                                            //console.log(getColumnText(grid.columns, attr) + ' => ' + record.data[attr]);
                                            console.log(colsConfig.colsObj[attr] + ' => ' + record.data[attr]);
                                        }
                                           
                                    });
                                       
                                    Ext.Array.each(grid.columns, function(record){
                                        //console.log(record);
                                    });
                                }
                            }]
                });


知识共享许可协议
《ExtJS4 获取表格汉字表头》常伟华 创作。
采用 知识共享 署名-相同方式共享 3.0 中国大陆 许可协议进行许可。
  • 多说评论
  • 签名
  • 新浪微博
  • 默认评论
  • Tab Header 5

0 条评论 / 点击此处发表评论

Tab Content 5

开发技术


开发平台和工具

sitemap     149.81ms