This article describes in detail how ExtJs sets up the vertical center of GridPanel table text. The specific implementation code is as follows. If you are interested, refer to the following code and hope to help you in business scenarios, the final implementation is as follows:
The GridPanel code is as follows:
The Code is as follows:
{
Xtype: 'grid ',
Id: 'grid _ jglb ',
Frame: true,
Region: 'center ',
Title: 'list details ',
ColumnLines: true,
LoadMask: true,
Store: 'test _ store ',
ViewConfig :{
ForceFit: true,
Scroloffset: 0
},
Anchor: '20140901 ',
SelModel: new Ext. grid. CheckboxSelectionModel ({
MoveEditorOnEnter: false,
Width: 28
}),
Columns :[{
Xtype: 'gridcolumn ',
Id: 'gridcolumn _ id ',
Align: 'center ',
DataIndex: 'column1 ',
Editable: false,
Header: 'column name 1 ',
Sortable: true,
Width: 100
},{
Xtype: 'gridcolumn ',
Align: 'center ',
DataIndex: 'column2 ',
Editable: false,
Header: 'column name 2 ',
Sortable: true,
Width: 100
},{
Xtype: 'gridcolumn ',
Align: 'center ',
DataIndex: 'column3 ',
Editable: false,
Header: 'column name 3 ',
Sortable: true,
Width: 100
},{
Xtype: 'gridcolumn ',
Align: 'center ',
DataIndex: 'column4 ',
Id: 'codecomx1 ',
Editable: false,
Header: 'column name 4 ',
Sortable: true,
Width: 100
},{
Xtype: 'gridcolumn ',
Align: 'center ',
DataIndex: 'column5 ',
Hidden: true,
Sortable: true
}],
Bbar :{
Xtype: 'paging ',
AutoShow: true,
DisplayInfo: true,
PageSize: 10,
Store: 'test _ store'
},
Tbar :[{
Text: 'add ',
IconCls: 'icon-add ',
Id: 'btn _ mxxz'
},'-',{
Text: 'modify ',
IconCls: 'icon-edit ',
Id: 'btn _ mxxg'
},'-',{
Text: 'delete ',
IconCls: 'icon-delete ',
Id: 'btn _ mxsc'
}]
}
The JsonStore code will not be pasted out. Next, let's take a look at how to implement vertical center.
Implementation idea: Get all the TD in the table by obtaining the DOM node and set the cssText value of the TD to 'text-align: center; lineheight: 130px; vertical-align: center ;'
Implementation basis: In Ext, The GridPanel container is rendered by generating DIV labels. Each line of record we see, for example, "test item, the "" row of data is a table in a p package. You only need to find the table based on Ext generation rules, and then you can operate its td element.
The implementation process is as follows:
The Code is as follows:
Ext. getCmp ("grid_jglb"). getStore (). on ('load', setTdCls); // after the table is loaded, change the table TD style to vertical center.
Function setTdCls (){
Var gridJglb = document. getElementById ("grid_jglb ");
Var tables = gridJglb. getElementsByTagName ("table"); // locate each table
For (var k = 0; k <tables. length; k ++ ){
Var tableV = tables [k];
If (tableV. className = "x-grid3-row-table "){
Var trs = tables [k]. getElementsByTagName ("tr"); // find each tr
For (var I = 0; I <trs. length; I ++ ){
Var tds = trs [I]. getElementsByTagName ("td"); // find each TD
For (var j = 1; j Tds1_j].style.css Text = "width: 202px; text-align: center; line-height: 130px; vertical-align: center ;";
}
}
};
}
}