123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- /**
- *
- * 固定普通table的行和列
- *
- *
- */
- if (typeof TableFix == 'undefined') {
- TableFix = {};
- };
- /**
- * 固定表头和列([tablefix='headRow']表示平台中的表头)
- *
- * @param tableId
- * @param fixColNum 需要固定的列数
- * @param width
- * @param height
- */
- TableFix.fix = function(tableId, fixColNum, width, height) {
- if ($("#" + tableId + "_tableLayout").length != 0) {
- $("#" + tableId + "_tableLayout").before($("#" + tableId));
- $("#" + tableId + "_tableLayout").empty();
- } else {
- $("#" + tableId).after("<div id='" + tableId + "_tableLayout' style='overflow:hidden;height:"
- + height + "px; width:" + width + "px;'></div>");
- }
- $('<div id="' + tableId + '_tableFix"></div>'
- + '<div id="' + tableId + '_tableHead"></div>'
- + '<div id="' + tableId + '_tableColumn"></div>'
- + '<div id="' + tableId + '_tableData"></div>')
- .appendTo("#" + tableId + "_tableLayout");
- var oldtable = $("#" + tableId);
- var tableFixClone = oldtable.clone(true);
- tableFixClone.attr("id", tableId + "_tableFixClone");
- $("#" + tableId + "_tableFix").append(tableFixClone);
- var tableHeadClone = oldtable.clone(true);
- tableHeadClone.attr("id", tableId + "_tableHeadClone");
- $("#" + tableId + "_tableHead").append(tableHeadClone);
- var tableColumnClone = oldtable.clone(true);
- tableColumnClone.attr("id", tableId + "_tableColumnClone");
- $("#" + tableId + "_tableColumn").append(tableColumnClone);
- $("#" + tableId + "_tableData").append(oldtable);
- $("#" + tableId + "_tableLayout table").each(function() {
- $(this).css("margin", "0");
- });
-
- var headHeight = 0;
- $("#" + tableId + "_tableHead").find("[tablefix='headRow']").each(function (){
- headHeight = headHeight + $(this).height();
- });
- $("#" + tableId + "_tableHead").css("height", headHeight);
- $("#" + tableId + "_tableFix").css("height", headHeight);
- var ColumnsWidth = 0;
- var ColumnsNumber = 0;
- $("#" + tableId + "_tableColumn tr:last td:lt(" + fixColNum + ")").each(function() {
- ColumnsWidth += $(this).outerWidth(true);
- ColumnsNumber++;
- });
- ColumnsWidth += 2;
- if ($.browser.msie) {
- switch ($.browser.version) {
- case "7.0":
- if (ColumnsNumber >= 3)
- ColumnsWidth--;
- break;
- case "8.0":
- if (ColumnsNumber >= 2)
- ColumnsWidth--;
- break;
- }
- }
- $("#" + tableId + "_tableColumn").css("width", ColumnsWidth);
- $("#" + tableId + "_tableFix").css("width", ColumnsWidth);
- $("#" + tableId + "_tableData").scroll(
- function() {
- $("#" + tableId + "_tableHead").scrollLeft(
- $("#" + tableId + "_tableData").scrollLeft());
- $("#" + tableId + "_tableColumn").scrollTop(
- $("#" + tableId + "_tableData").scrollTop());
- });
- $("#" + tableId + "_tableFix").css({
- "overflow" : "hidden",
- "position" : "relative",
- "z-index" : "50",
- "background-color" : "Silver"
- });
- $("#" + tableId + "_tableHead").css({
- "overflow" : "hidden",
- "width" : width - 17,
- "position" : "relative",
- "z-index" : "45",
- "background-color" : "Silver"
- });
- $("#" + tableId + "_tableColumn").css({
- "overflow" : "hidden",
- "height" : height - 17,
- "position" : "relative",
- "z-index" : "40",
- "background-color" : "Silver"
- });
- $("#" + tableId + "_tableData").css({
- "overflow" : "auto",
- "width" : width,
- "height" : height,
- "position" : "relative",
- "z-index" : "35"
- });
- if ($("#" + tableId + "_tableHead").width() > $(
- "#" + tableId + "_tableFix table").width()) {
- $("#" + tableId + "_tableHead").css("width",
- $("#" + tableId + "_tableFix table").width());
- $("#" + tableId + "_tableData").css("width",
- $("#" + tableId + "_tableFix table").width() + 17);
- }
- if ($("#" + tableId + "_tableColumn").height() > $(
- "#" + tableId + "_tableColumn table").height()) {
- $("#" + tableId + "_tableColumn").css("height",
- $("#" + tableId + "_tableColumn table").height());
- $("#" + tableId + "_tableData").css("height",
- $("#" + tableId + "_tableColumn table").height() + 17);
- }
- $("#" + tableId + "_tableFix").offset(
- $("#" + tableId + "_tableLayout").offset());
- $("#" + tableId + "_tableHead").offset(
- $("#" + tableId + "_tableLayout").offset());
- $("#" + tableId + "_tableColumn").offset(
- $("#" + tableId + "_tableLayout").offset());
- $("#" + tableId + "_tableData").offset(
- $("#" + tableId + "_tableLayout").offset());
-
-
- $("#" + tableId + "_tableFixClone").find("[name]").removeAttr("name");
- $("#" + tableId + "_tableHeadClone").find("[name]").removeAttr("name");
- $("#" + tableId + "_tableColumnClone").find("[name]").removeAttr("name");
- $("#" + tableId + "_tableFixClone").find("[formtype]").removeAttr("formtype");
- $("#" + tableId + "_tableHeadClone").find("[formtype]").removeAttr("formtype");
- $("#" + tableId + "_tableColumnClone").find("[formtype]").removeAttr("formtype");
-
- }
- /**
- * 还原改变后的表
- *
- * @param tableId
- */
- TableFix.restore = function(tableId) {
- var table = $("#" + tableId);
- var tableClone = table.clone(true);
- $("#" + tableId + "_tableLayout").after(tableClone);
- $("#" + tableId + "_tableLayout").remove();
- }
|