Reference declaration:
The essence of this effect is to use CSS to remove borders without the grouping function.
Code passed test in IE6-8, ff3
Code depends on extjs 3.x
1. Add a CSS style
Java code
- /* Rowspan grid merge row effect */
- . Rowspan-grid. x-grid3-body. x-grid3-row {
- Border: none;
- Cursor: default;
- Width: 100%;
- }
- . Rowspan-grid. x-grid3-header. x-grid3-cell {
- /* Border-left: 2px solid transparent; * // * The transparent of IE6 is black? */
- Border-left: 2px solid # FFF;
- }
- . Rowspan-grid. x-grid3-body. x-grid3-row {
- Overflow: hidden;
- Border-Right: 1px solid # CCC;
- }
- . Rowspan-grid. x-grid3-body. x-grid3-cell {
- Border: 1px solid # CCC;
- Border-top: none;
- Border-Right: none;
- }
- . Rowspan-grid. x-grid3-body. x-grid3-cell-first {
- /* Border-left: 1px solid transparent ;*/
- Border-left: 1px solid # FFF;
- }
- . Rowspan-grid. The x-grid3-body. rowspan-unborder {
- /* Border-bottom: 1px solid transparent ;*/
- Border-bottom: 1px solid # FFF;
- }
- . Rowspan-grid. x-grid3-body. rowspan {
- Border-bottom: 1px solid # CCC;
- }
2. Introduce Ext. UX. Grid. rowspanview object
Java code
- Ext. NS ('ext. UX. grid ');
- /**
- * Implement the rowspan effect of the grid.
- * @ Author: tipx.iteye.com
- *
- * 1. in the column model, you need to configure the rowspan attribute in the columns of the merged rows, for example, {dataindex: 'xxx', header: 'xxx', rowspan: 3} // merge one row for each three rows of the column
- * 2. Set view attribute => View: New Ext. UX. Grid. rowspanview () for Grid ()
- * 3. Set the CLS attribute => CLS: 'rowspan-grid' for the grid'
- * 4. Add a CSS style
- */
- Ext. UX. Grid. rowspanview = ext. Extend (ext. Grid. gridview ,{
- Constructor: function (CONF ){
- Ext. UX. Grid. rowspanview. superclass. constructor. Call (this, conf );
- },
- // Private
- // Clear the data of a non-First row in the merged row
- Cleanrenderer: function (column, value, metadata, record, rowindex, colindex, store ){
- VaR rowspan = column. rowspan;
- If (! Ext. isempty (rowspan) & rowspan! = 0 ){
- If (rowindex % rowspan! = 0 ){
- Return '';
- }
- }
- Return column. Renderer (value, metadata, record, rowindex, colindex, store );
- },
- // Private
- Dorender: function (CS, RS, DS, startrow, colcount, stripe ){
- VaR Ts = This. templates, Ct = ts. Cell, rT = ts. Row, last = colCount-1;
- VaR tstyle = 'width: '+ this. gettotalwidth () + ';';
- // Buffers
- VaR Buf = [], CB, C, P = {}, Rp = {tstyle: tstyle}, R;
- // Cmconfig column Model
- VaR cmconfig = This. cm. config, rowspans = [];
- For (VAR I = 0, Len = cmconfig. length; I <Len; I ++ ){
- Rowspans. Push (math. Max (cmconfig [I]. rowspan | 0), 0 ));
- }
- For (var j = 0, Len = Rs. length; j <Len; j ++ ){
- R = Rs [J]; Cb = [];
- VaR rowindex = (J + startrow );
- For (VAR I = 0; I <colcount; I ++ ){
- C = cs [I];
- P. ID = C. ID;
- P.css = I = 0? 'X-grid3-cell-first ': (I = last? 'X-grid3-cell-last ':'');
- P. ATTR = P. cellattr = "";
- P. value = This. cleanrenderer (cmconfig [I], R. Data [C. name], P, R, rowindex, I, DS );
- P. Style = C. style;
- If (ext. isempty (P. Value )){
- P. value = "& #160 ;";
- }
- If (this. markdirty & R. Dirty & typeof R. Modified [C. Name]! = 'Undefined '){
- P.css + = 'x-grid3-dirty-cell ';
- }
- //------------------------------------------------
- // Add the rowspan class and use styles to merge rows.
- If (rowspans [I]! = 0 ){
- // Add the rowspan class to each rowspan row and the last row, that is, add the border-bottom
- If (j = (len-1) | (rowindex + 1) % rowspans [I] = 0 ){
- P.css + = 'rowspan ';
- } Else {
- P.css + = 'rowspan-unborder ';
- }
- }
- //------------------------------------------------
- CB [CB. Length] = CT. Apply (P );
- }
- VaR alt = [];
- If (stripe & (rowindex + 1) % 2 = 0 )){
- Alt [0] = "x-grid3-row-alt ";
- }
- If (R. Dirty ){
- Alt [1] = "x-grid3-dirty-row ";
- }
- RP. Cols = colcount;
- If (this. getrowclass ){
- Alt [2] = This. getrowclass (R, rowindex, RP, DS );
- }
- RP. Alt = alt. Join ("");
- RP. Cells = CB. Join ("");
- Buf [Buf. Length] = rt. Apply (RP );
- }
- Return Buf. Join ("");
- }
- });
3. Create a grid
A. when creating a column model, add the configuration "rowspan: number of rows" (excluding double quotation marks) to the column model that requires merging rows)
Java code
- {Header: 'company', dataindex: 'company', rowspan: 4} // merge every four rows of this column into one row
B. When creating a grid, configure "CLS: 'rowspan-grid', view: New Ext. UX. Grid. rowspanview ()" for the grid ()"
Java code
- // Create the grid
- VaR grid = new Ext. Grid. gridpanel ({
- Title: 'extjs row merging (rowspan) effect ',
- Store: store,
- SM: Sm,
- CM: cm,
- Striperows: True,
- CLS: 'rowspan-grid', // This style must be configured ******
- View: New Ext. UX. Grid. rowspanview () // *** use View
- });
4. Preview results
5. Flaws
Because the Box Model of browsers other than IE6 is weird (the main reason is that I am not good at CSS ), the column header is not aligned with the border of the data column (the current effect is already the best effort );
Because "border-left: 2px solid
The transparent in transparent is black under IE6, and I am not good at hack (=. = I don't know what I am good .)
All transparent is replaced with white (the effect will be worse). If you can directly hack IE6, it should be a little more perfect.
6. Note
As can be seen from the above, only the first row of data in the merged row is displayed in the merged row area, but this is not the grouping effect! Instead, the cleanrenderer method in the view directly returns the empty string "non-first row of data in the X rowspan region. Not merge the same data!
7. Download demo
See Attachment