0

如何在 extjs 6.2.0 中按标题(标题)设置列宽?

我想通过标题内容自动设置列宽

4

2 回答 2

0

如您所见,我创建了一个函数 getColumnWidth(),它将网格列文本作为参数,然后返回列宽。

您还可以根据需要调整 getColumnWidth() 中的数字。

Sencha Fiddle 链接https://fiddle.sencha.com/#view/editor&fiddle/2l1r

Ext.application({
    name : 'Fiddle',
    launch : function() {
        Ext.create('Ext.window.Window',{
		title:'Grid Auto Fit Column Width Based on Header Text',
		width:600,
		height:400,
		autoShow:true,
		layout:'fit',
		items:[{
		    xtype:'grid',
		    columns:[
		        {
		            text:'id',
		            width:this.getColumnWidth('id'),
		        },{
		            text:'Name',
		            width:this.getColumnWidth('Name'),
		        },{
	                text:'ThisWillFitItsData',
		            width:this.getColumnWidth('ThisWillFitItsData')
		        },{
	                text:'LetsTryMoreLongerText',
		            width:this.getColumnWidth('LetsTryMoreLongerText')
		        },{
		            text:'Fixed',
		            width:60
		        }
		        ]
		    }]
	});
    },
    getColumnWidth:function(text){
        let columnWidth = (text.length * 7) + 35  // giving 7 pixles for each letter in the text
        //Optional This part is used to set a maximum column width in case there is too many charachter in the text
        if(columnWidth>400){
            columnWidth = 400
        }
        return columnWidth;
    }
});

于 2018-09-03T17:04:59.057 回答
0

列的宽度必须为空:

var c = Ext.create('Ext.grid.column.Column', { text: 'Nam12131231313e', dataIndex: 'name', width: null});

于 2018-08-31T08:49:37.270 回答