Ext雖能夠去除相同的單元格,但右側數據左移致使grid錯亂,有待解決。。。css
/** * Kunoy * 合併單元格 * @param {} grid 要合併單元格的grid對象 * @param {} cols 要合併哪幾列 [1,2,4] */ var mergeCells = function(grid,cols) { var gridid = '#' + grid.getId() + '-body'; var arrayTr = $('tr', $(gridid)); var trCount = arrayTr.length; var arrayTd; var td; var merge = function(rowspanObj, removeObjs) { //定義合併函數 if (rowspanObj.rowspan != 1) { debugger; var colName = grid.columns[rowspanObj.td - 1].dataIndex;// colName.dataIndex arrayTd = arrayTr[rowspanObj.tr].getElementsByTagName("td"); //合併行 td = arrayTd[rowspanObj.td - 1]; td.rowSpan = rowspanObj.rowspan; td.vAlign = "middle"; Ext.each(removeObjs, function(obj) { //隱身被合併的單元格 debugger; arrayTd = arrayTr[obj.tr].getElementsByTagName("td"); arrayTd[obj.td-1].style.display='none'; //arrayTd[obj.td-1].style.borderTop = "none"; arrayTd[obj.td-1].style.backgroundColor = '#6633FF'; arrayTd[obj.td - 1].innerText = ''; $(arrayTd[obj.td - 1]).css("border-top",'1px solid red'); }); } }; var rowspanObj = {}; //要進行跨列操做的td對象{tr:1,td:2,rowspan:5} var removeObjs = []; //要進行刪除的td對象[{tr:2,td:2},{tr:3,td:2}] var col; Ext.each(cols, function(colIndex) { //逐列去操做tr var rowspan = 0; var divHtml = null; //單元格內的數值 //debugger; for ( var i = 0; i < trCount; i++) { //i=0表示表頭等沒用的行 arrayTd = arrayTr[i].getElementsByTagName("td"); var cold = 0; col = colIndex + cold; //跳過RowNumber列和check列 if (!divHtml) { divHtml = arrayTd[col - 1].innerHTML; rowspanObj = { tr : i, td : col, rowspan : rowspan } } else { var cellText = arrayTd[col - 1].innerHTML; var addf = function() { //debugger; rowspanObj["rowspan"] = rowspanObj["rowspan"] + 1; removeObjs.push({ tr : i, td : col }); if (i == trCount - 1) merge(rowspanObj, removeObjs); //執行合併函數 }; var mergef = function () { merge(rowspanObj, removeObjs); //執行合併函數 divHtml = cellText; rowspanObj = { tr: i, td: col, rowspan: rowspan } removeObjs = []; }; if (cellText == divHtml) { if(colIndex!=cols[0]){ mergef(); }else addf(); }else{ mergef(); } } } }); };
grid加載數據完成後自動調用合併方法java
duplicateQueryStore.on('load',function(){ //==>防止Grid重繪, 人工延遲 setTimeout(function(){ mergeCells(Ext.getCmp('duplicateGridId'),[6,7,8,9]); },150); });
注:可在Chorme瀏覽器上按F12鍵,經過debugger進行調試。瀏覽器