自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Qt TableWidget 固定表頭 實例

移動開發(fā)
本文介紹的是Qt TableWidget 固定表頭 實例,很多時候我們都在用列表,不多說,先哎看本文內容。

Qt TableWidget 固定表頭 實例是本文要介紹的內容,使TableWidget  固定表頭一個js插件的實例,先來看內容。

公司項目里面很多地方都需要用到,出列表的時候固定表頭,滾動表體,思路就是動態(tài)創(chuàng)建一個div,然后里面創(chuàng)建2個div,一個title,一個body,然后用clone的方法,分別處理2個div的內容

使用說明:

  1. var tableWidget = new TableWidget("TableID", "DestID", "100%", "300px");  
  2. tableWidget.change(); 

表格需要固定寬度,table 需要加 style="table-layout: fixed;"

  1. /*  
  2. * 函數名稱: Widget  
  3. * 作    者: yithcn  
  4. * 功能說明: 固定表格頭,表體可以滾動  
  5. * 創(chuàng)建日期: 2010.10.13  
  6. */  
  7. function TableWidget(table, dest, width, height) {  
  8.     this.construct(table, dest, width, height);  
  9. };  
  10. TableWidget.prototype = {  
  11.     table: null,  
  12.     dest: null,  
  13.     widht: null,  
  14.     height: null,  
  15.     tdiv: null,  
  16.     bdiv: null,  
  17.     create: function() {  
  18.         var that = this;  
  19.         var div = document.createElement("div");  
  20.         div.style.cssText = "background-color:white;width:" + that.width;  
  21.         that.dest.appendChild(div);  
  22.         //title  
  23.         var titlediv = document.createElement("div");  
  24.         titlediv.style.cssText = "width:100%;";  
  25.         div.appendChild(titlediv);  
  26.         //body  
  27.         var bodydiv = document.createElement("div");  
  28.         bodydiv.style.cssText = "overflow:auto;height:" + that.height + ";";  
  29.         bodydiv.appendChild(that.table);  
  30.         div.appendChild(bodydiv);  
  31.         var newtable = that.table.cloneNode(true);  
  32.         var len = newtable.rows.length;  
  33.         for (var i = len - 1; i > 0; i--) {  
  34.             newtable.deleteRow(i);  
  35.         }  
  36.         titlediv.appendChild(newtable);  
  37.         that.table.deleteRow(0);  
  38.         that.tdiv = titlediv;  
  39.         that.bdiv = bodydiv;  
  40.     },  
  41.     construct: function(table, dest, width, height) {  
  42.         var that = this;  
  43.         window.onload = function() {  
  44.             if (table && typeof table == "string")  
  45.                 table = document.getElementById(table);  
  46.             if (dest && typeof dest == "string")  
  47.                 dest = document.getElementById(dest);  
  48.             else  
  49.                 dest = document.body;  
  50.             widthwidth = width || "100%";  
  51.             heightheight = height || "300px";  
  52.             height = parseInt(height) - table.rows[0].offsetHeight;  
  53.             that.table = table;  
  54.             that.dest = dest;  
  55.             that.width = width;  
  56.             that.height = height;  
  57.             that.create();  
  58.             that.change();  
  59.         }  
  60.     },  
  61.     change: function() {  
  62.         var that = this;  
  63.         if (that.table.offsetHeight > parseInt(that.height)) {  
  64.             that.tdiv.style.width = parseInt(that.bdiv.offsetWidth) - 16;  
  65.         }  
  66.         else {  
  67.             that.tdiv.style.width = parseInt(that.bdiv.offsetWidth);  
  68.         }  
  69.     }  
  70. }; 

之所以會有一個change方法,是因為在項目當中需要動態(tài)改變列表,要計算表頭和表體滾動條。

小結:Qt TableWidget 固定表頭 實例的內容介紹完了, 希望本文對你有所幫助!

責任編輯:zhaolei 來源: 互聯(lián)網
相關推薦

2011-06-30 14:34:17

QT Tablewidge QTableWidg

2011-06-30 16:53:18

QT Creator TableWidge

2009-06-23 11:23:13

DataTableJSF動態(tài)生成

2011-07-05 14:46:34

2011-06-27 16:07:49

Qt Designer

2011-06-21 09:33:49

Qt 啟動 界面

2011-06-14 16:45:57

Qt 圖標

2011-06-24 14:34:17

Qt 小票 打印

2011-06-13 16:51:19

Qt Socket

2011-06-27 16:37:08

Qt Designer

2011-06-30 11:07:02

Qt QTextEdit

2011-06-16 17:54:30

Qt Mplayer

2014-08-26 11:46:46

QtAndroid實例教程

2011-06-30 18:15:36

Qt 線程 同步

2011-07-05 15:16:00

QT 進度條

2011-06-30 17:31:32

Qt 多線程 信號

2011-06-21 15:11:04

QT 數據庫

2011-06-30 16:38:07

Qt QTableWidg

2011-06-14 10:52:10

QT QTreeView

2011-06-29 11:06:12

Qt Qvfb
點贊
收藏

51CTO技術棧公眾號