datagrid小tip(二):拼接多層表頭

來源:互聯網
上載者:User
<script language="javascript">
        //初始化表頭,產生雙層表頭    
        window.onload = function()
        {
            var obj = document.getElementById("DataGrid1");            
            if(obj != undefined)
            {
                var row=obj.insertRow(0);
                row.className = "headStyle";
                var Cell1 = row.insertCell();
                Cell1.innerText = "單位";
                Cell1.rowSpan = 3;
                
                var Cell2 = row.insertCell();
                Cell2.innerText = "在職";
                Cell2.colSpan=4;                
                
                var Cell3 = row.insertCell();
                Cell3.innerText = "退休";
                Cell3.colSpan = 4;
                
                var Cell4 = row.insertCell();
                Cell4.innerText = "合計";
                Cell4.colSpan = 2;    
                Cell4.rowSpan=2;    
                
                var row1=obj.insertRow(1);
                row1.className = "headStyle";
                
                
                var Cell5 = row1.insertCell();    
                Cell5.innerText = "<=45";    
                Cell5.colSpan = 2;        
                var Cell6 = row1.insertCell();    
                Cell6.innerText = ">45";    
                Cell6.colSpan = 2;    
                
                var Cell7 = row1.insertCell();    
                Cell7.innerText = "<=65";
                Cell7.colSpan = 2;        
                var Cell8 = row1.insertCell();    
                Cell8.innerText = ">65";    
                Cell8.colSpan = 2;        
                
                obj.rows[2].deleteCell(0);    
                
            }
        }
        </script>

datagrid的繫結資料行的表頭可以正常寫,然後用Javascript畫出需要的多層表頭.這段代碼的最重要的一步就是對是否存在datagrid的判定,因為如果後台代碼不是開始load頁面的時候就綁定datagrid並顯示的話,這段代碼會報錯.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.