Permalink
Browse files

feat: 增加参数rowHeight、sumRowHeight、headerHeight用于控制行高

  • Loading branch information...
LiuYueKai committed Apr 20, 2017
1 parent 48efee1 commit b9406b82c73ed01938c9617a72667733e05be039
View
@@ -112,7 +112,7 @@ header区域css begin
}
.u-grid-header-th {
vertical-align: bottom;
- height: 2.75em;
+ /*height: 2.75em;*/
font-weight: normal;
overflow: hidden;
white-space: nowrap;
@@ -320,7 +320,6 @@ content区域css begin
}
.u-grid-content-left-sum-first{
- bottom:0px;
border-style: solid;
border-color: #cecece;
border-width: 0px;
View
@@ -218,8 +218,14 @@ const createThead = function(createFlag) {
// 低版本浏览器不支持th position为relative,因此加入空div
htmlStr += '<th role="columnheader" data-filed="' + this.options.field + '" rowspan="1" class="u-grid-header-th ' + thLevelClass + '" ' + displayStyle + 'field="' + this.options.field + '" index="' + i + '" visibleIndex="' + vi + '"><div style="position:relative;" class="u-grid-header-div">';
var colorStype = '';
- if (this.options.headerColor) {
- colorStype = 'style="color:' + this.options.headerColor + '"';
+ if (this.options.headerColor || oThis.options.headerHeight) {
+ var headerC = '';
+ var headerH = '';
+ if (this.options.headerColor)
+ headerC = 'color:' + this.options.headerColor + ';';
+ if (oThis.options.headerHeight)
+ headerH = 'height:' + oThis.options.headerHeight + 'px;line-height:' + oThis.options.headerHeight + 'px;';
+ colorStype = 'style="' + headerC + headerH + '"';
}
htmlStr += '<div class="u-grid-header-link" field="' + this.options.field + '" ' + colorStype + '>' + this.options.title + '</div>';
/*if(oThis.options.columnMenu && createFlag != 'fixed'){
@@ -284,21 +290,26 @@ const createContentLeft = function() {
var oThis = this,
htmlStr = "",
left = 0,
- hStr, sumRowClass = '';
+ hStr = "",
+ sumRowClass = '',
+ topStr = "";
// 高度可伸缩,暂时去掉内部的高度设置
// if(this.countContentHeight && parseInt(this.contentHeight) > 0){
// hStr = 'max-height:' + this.contentHeight + 'px;overflow:hidden;';
// }else{
// hStr = '';
// }
+ if (this.options.showSumRow && this.options.sumRowFirst && this.options.sumRowHeight) {
+ topStr = "top:" + this.options.sumRowHeight + 'px';
+ }
if (this.options.showSumRow) {
sumRowClass = 'u-grid-content-left-sum';
- if(this.options.sumRowFirst){
- sumRowClass += ' u-grid-content-left-sum-first';
+ if (this.options.sumRowFirst) {
+ sumRowClass += ' u-grid-content-left-sum-first';
}
}
if (this.options.multiSelect) {
- htmlStr += '<div class="u-grid-content-left ' + sumRowClass + '" id="' + this.options.id + '_content_multiSelect" style="width:' + this.multiSelectWidth + 'px;' + hStr + '">';
+ htmlStr += '<div class="u-grid-content-left ' + sumRowClass + '" id="' + this.options.id + '_content_multiSelect" style="width:' + this.multiSelectWidth + 'px;' + hStr + topStr + '">';
// 遍历生成所有行
if (this.dataSourceObj.rows) {
$.each(this.dataSourceObj.rows, function(i) {
@@ -309,7 +320,7 @@ const createContentLeft = function() {
left += this.multiSelectWidth;
}
if (this.options.showNumCol) {
- htmlStr += '<div class="u-grid-content-left ' + sumRowClass + '" id="' + this.options.id + '_content_numCol" style="width:' + this.numWidth + 'px;left:' + left + 'px;' + hStr + '">';
+ htmlStr += '<div class="u-grid-content-left ' + sumRowClass + '" id="' + this.options.id + '_content_numCol" style="width:' + this.numWidth + 'px;left:' + left + 'px;' + hStr + topStr + '">';
// 遍历生成所有行
if (this.dataSourceObj.rows) {
$.each(this.dataSourceObj.rows, function(i, row) {
@@ -619,8 +630,17 @@ const createContentOneRowTd = function(row, createFlag) {
}
if (!this.options.visible) {
- tdStyle = 'style="display:none;"';
+ tdStyle = 'style="display:none;';
+ if (oThis.options.rowHeight) {
+ tdStyle += 'height:' + oThis.options.rowHeight + 'px;line-height:' + oThis.options.rowHeight + 'px;';
+ }
+ tdStyle += '"';
+ } else {
+ if (oThis.options.rowHeight) {
+ tdStyle += 'style="height:' + oThis.options.rowHeight + 'px;line-height:' + oThis.options.rowHeight + 'px;"';
+ }
}
+
if (this.options.icon) {
iconStr = '<span class="' + this.options.icon + '"></span>';
}
@@ -673,6 +693,10 @@ const createContentOneRowTdForIE = function(row, rowObj, createFlag) {
if (!this.options.visible) {
newCell.style.display = "none";
}
+ if (oThis.options.rowHeight) {
+ newCell.style.height = oThis.options.rowHeight + 'px';
+ newCell.style.lineHeight = oThis.options.rowHeight + 'px';
+ }
if (this.options.icon) {
iconStr = '<span class="' + this.options.icon + '"></span>';
}
@@ -1,18 +1,18 @@
const trHoverFun = function(index) {
var oThis = this;
- $('#' + oThis.options.id + '_content_tbody').find('tr').removeClass('u-grid-move-bg');
- $('#' + oThis.options.id + '_content_fixed_tbody').find('tr').removeClass('u-grid-move-bg');
+ $('#' + oThis.options.id + '_content_tbody').find('tr[role="row"]').removeClass('u-grid-move-bg');
+ $('#' + oThis.options.id + '_content_fixed_tbody').find('tr[role="row"]').removeClass('u-grid-move-bg');
if (oThis.options.multiSelect)
$('#' + oThis.options.id + '_content_multiSelect').find('div').removeClass('u-grid-move-bg');
if (oThis.options.showNumCol)
$('#' + oThis.options.id + '_content_numCol').find('div').removeClass('u-grid-move-bg');
if (index > -1) {
- var $tr = $('#' + oThis.options.id + '_content_tbody').find('tr').eq(index);
+ var $tr = $('#' + oThis.options.id + '_content_tbody').find('tr[role="row"]').eq(index);
if ($tr[0].id && $tr[0].id == oThis.options.id + '_edit_tr') {
return;
}
- $('#' + oThis.options.id + '_content_tbody').find('tr').eq(index).addClass('u-grid-move-bg');
- $('#' + oThis.options.id + '_content_fixed_tbody').find('tr').eq(index).addClass('u-grid-move-bg');
+ $('#' + oThis.options.id + '_content_tbody').find('tr[role="row"]').eq(index).addClass('u-grid-move-bg');
+ $('#' + oThis.options.id + '_content_fixed_tbody').find('tr[role="row"]').eq(index).addClass('u-grid-move-bg');
if (oThis.options.multiSelect)
$('#' + oThis.options.id + '_content_multiSelect').find('div').eq(index).addClass('u-grid-move-bg');
if (oThis.options.showNumCol)
@@ -84,10 +84,16 @@ const resetLeftHeightFun = function() {
var $leftSelects = $('#' + this.options.id + '_content_multiSelect > div');
for (var i = 0; i < $trs.length; i++) {
var nowRowHeight = $trs[i].offsetHeight;
- if ($leftNums[i])
+ if ($leftNums[i]) {
$leftNums[i].style.height = nowRowHeight + 'px';
- if ($leftSelects[i])
+ // $leftNums[i].style.lineHeight = nowRowHeight + 'px';
+ }
+
+ if ($leftSelects[i]) {
$leftSelects[i].style.height = nowRowHeight + 'px';
+ // $leftSelects[i].style.lineHeight = nowRowHeight + 'px';
+ }
+
}
}
}
View
@@ -52,6 +52,7 @@ const initContentDivEventFun = function() {
});
// 同步滚动条
$('#' + this.options.id + '_content_div').on('scroll', function(e) {
+ var sumRowH = 0;
oThis.scrollLeft = this.scrollLeft;
oThis.scrollTop = this.scrollTop;
if (oThis.options.fixedFloat == 'right') {
@@ -61,9 +62,14 @@ const initContentDivEventFun = function() {
}
$('#' + oThis.options.id + '_noRowsShow').css('left', oThis.scrollLeft + "px");
$('#' + oThis.options.id + '_edit_form').css('left', oThis.scrollLeft + "px");
- $('#' + oThis.options.id + '_content_multiSelect').css('top', -oThis.scrollTop + "px");
- $('#' + oThis.options.id + '_content_numCol').css('top', -oThis.scrollTop + "px");
- $('#' + oThis.options.id + '_content_fixed_div').css('top', -oThis.scrollTop + "px");
+ if (oThis.options.showSumRow && oThis.options.sumRowFirst) {
+ sumRowH = 44;
+ if (oThis.options.sumRowHeight)
+ sumRowH = oThis.options.sumRowHeight;
+ }
+ $('#' + oThis.options.id + '_content_multiSelect').css('top', -oThis.scrollTop + sumRowH + "px");
+ $('#' + oThis.options.id + '_content_numCol').css('top', -oThis.scrollTop + sumRowH + "px");
+ $('#' + oThis.options.id + '_content_fixed_div').css('top', -oThis.scrollTop + "px");
if (gridBrowser.isIE10 || gridBrowser.isIPAD) {
//ie10下示例系统中的档案节点新增数据之后前两次无法输入,因为此处会关闭输入控件
} else {
View
@@ -46,7 +46,7 @@ const init = function(ele, options) {
this.columnMenuHeight = 33; // column menu的高度
this.gridCompColumnFixedArr = new Array(); // 存储设置默认值之后的固定列columns对象
this.gridCompLevelColumn = new Array(); // 存储多级表头时的多级
- this.baseHeaderHeight = 44;
+ this.baseHeaderHeight = this.options.headerHeight || 44;
this.headerHeight = this.baseHeaderHeight * parseInt(this.options.maxHeaderLevel) + 1;
this.gridCompHiddenLevelColumnArr = new Array(); // 存储自动隐藏时隐藏优先级排序后的column
this.treeLeft = 10; // 树表时每一级之间的差值
@@ -105,6 +105,9 @@ const initDefault = function() {
showEditIcon: false, // 是否显示编辑图标
contentFocus: true, // 点击内容区是否执行focus逻辑
fixedFloat: 'left',
+ // rowHeight 行高
+ // sumRowHeight 合计行行高
+ // headerHeight 表头高
}
};
/*
@@ -166,6 +169,9 @@ const initOptions = function() {
this.options.canDrag = false;
this.options.columnMenu = false;
}
+ if (this.options.rowHeight && !this.options.sumRowHeight) {
+ this.options.sumRowHeight = this.options.rowHeight;
+ }
// 获取缓存id
var url = window.location.href;
var index = url.indexOf('?');
Oops, something went wrong.

0 comments on commit b9406b8

Please sign in to comment.