Permalink
Browse files

feat: 增加参数支持整体宽度大于所有显示列宽度时非最后一列也可以自动扩展宽度

  • Loading branch information...
LiuYueKai committed Jun 23, 2017
1 parent 28d7a43 commit 175e98de180dc667232a2ac3913fcf622d339fb0
Showing with 51 additions and 25 deletions.
  1. +1 −0 src/js/gridCompCreateCal.js
  2. +1 −0 src/js/gridCompInit.js
  3. +14 −5 src/js/gridCompOther.js
  4. +30 −17 src/js/gridCompSet.js
  5. +3 −3 src/js/re_gridCompSort.js
  6. +2 −0 src/js/re_gridCompSwap.js
@@ -54,6 +54,7 @@ const afterGridDivsCreate = function() {
this.hideEditMenu();
this.resetLeftHeight();
this.isCheckedHeaderRow();
this.resetColumnWidthByRealWidth();
if (typeof this.options.afterCreate == 'function') {
this.options.afterCreate.call(this);
}
View
@@ -113,6 +113,7 @@ const initDefault = function() {
needResetHeight: false, // 是否需要根据右侧内容高度调整左侧高度,目前为false,后续提供方案之后再处理此参数
treeAsync: false, //树表异步加载数据
heightAuto: false, // 内容自动撑高
expandColumnIndex: 0,
// sumRowHeight 合计行行高
// headerHeight 表头高
// maxHeight heightAuto为true时的最大高度
View
@@ -52,14 +52,16 @@ const columnsVisibleFun = function() {
const resetLastVisibleColumnWidth = function() {
var allVisibleColumns = this.getAllVisibleColumns();
var l = allVisibleColumns.length;
var w = 0;
var lastW = 0;
for (var i = 0; i < allVisibleColumns.length; i++) {
var column = allVisibleColumns[i];
if (i < (allVisibleColumns.length - 1)) {
w += column.options.width;
} else {
if (i == l - 1 - this.options.expandColumnIndex) {
lastW = column.options.realWidth;
this.lastVisibleColumn = column;
} else {
w += column.options.width;
}
}
if (w < this.contentMinWidth) {
@@ -69,8 +71,15 @@ const resetLastVisibleColumnWidth = function() {
}
this.lastVisibleColumnWidth = lastW;
this.lastVisibleColumn.options.width = lastW;
$('#' + this.options.id + '_header_table col:last').css('width', this.lastVisibleColumnWidth + "px");
$('#' + this.options.id + '_content_table col:last').css('width', this.lastVisibleColumnWidth + "px");
if (this.options.expandColumnIndex == 0) {
$('#' + this.options.id + '_header_table col:last').css('width', this.lastVisibleColumnWidth + "px");
$('#' + this.options.id + '_content_table col:last').css('width', this.lastVisibleColumnWidth + "px");
}else{
var eqIndex = l - this.options.expandColumnIndex -1;
$('#' + this.options.id + '_header_table col:eq(' + eqIndex + ')').css('width', this.lastVisibleColumnWidth + "px");
$('#' + this.options.id + '_content_table col:eq(' + eqIndex + ')').css('width', this.lastVisibleColumnWidth + "px");
}
};
/*
* 创建完成之后处理变量
View
@@ -12,8 +12,9 @@ const setColumnVisibleByIndex = function(index, visible) {
if (index >= 0) {
var column = this.gridCompColumnArr[index],
visibleIndex = this.getVisibleIndexOfColumn(column),
canVisible = column.options.canVisible;
if (!canVisible) {
canVisible = column.options.canVisible,
l = $('input:checked', $('#' + this.options.id + '_column_menu_columns_ul')).length;
if (!canVisible || (l == 1 && visible == false)) {
return;
}
// 显示处理
@@ -87,6 +88,18 @@ const setColumnVisibleByIndex = function(index, visible) {
}
this.resetColumnWidthByRealWidth();
this.saveGridCompColumnArrToLocal();
var columnAllCheck = $('input', $('#' + this.options.id + '_column_menu_ul .header'));
if (columnAllCheck.length > 0) {
var lll = $('input:not(:checked)', $('#' + this.options.id + '_column_menu_columns_ul')).length;
if (lll > 0) {
columnAllCheck[0].checked = false;
} else {
columnAllCheck[0].checked = true;
}
}
}
};
@@ -113,21 +126,21 @@ const setCoulmnWidthByField = function(field, newWidth) {
*/
const setColumnWidth = function(column, newWidth) {
// if (column != this.lastVisibleColumn) {
if (newWidth > this.minColumnWidth || newWidth == this.minColumnWidth) {
var nowVisibleThIndex = this.getVisibleIndexOfColumn(column),
oldWidth = column.options.width,
changeWidth = newWidth - oldWidth,
cWidth = this.contentWidth + changeWidth;
this.contentWidth = this.contentWidthChange(cWidth);
$('#' + this.options.id + '_header_table col:eq(' + nowVisibleThIndex + ')').css('width', newWidth + "px");
$('#' + this.options.id + '_content_table col:eq(' + nowVisibleThIndex + ')').css('width', newWidth + "px");
column.options.width = newWidth;
column.options.realWidth = newWidth;
this.resetThVariable();
this.saveGridCompColumnArrToLocal();
}
this.resetLastVisibleColumnWidth();
this.columnsVisibleFun();
if (newWidth > this.minColumnWidth || newWidth == this.minColumnWidth) {
var nowVisibleThIndex = this.getVisibleIndexOfColumn(column),
oldWidth = column.options.width,
changeWidth = newWidth - oldWidth,
cWidth = this.contentWidth + changeWidth;
this.contentWidth = this.contentWidthChange(cWidth);
$('#' + this.options.id + '_header_table col:eq(' + nowVisibleThIndex + ')').css('width', newWidth + "px");
$('#' + this.options.id + '_content_table col:eq(' + nowVisibleThIndex + ')').css('width', newWidth + "px");
column.options.width = newWidth;
column.options.realWidth = newWidth;
this.resetThVariable();
this.saveGridCompColumnArrToLocal();
}
this.resetLastVisibleColumnWidth();
this.columnsVisibleFun();
// }
};
/*
@@ -89,14 +89,14 @@ const canSortable = function(e, ele) {
//$(ele.firstChild)[0].insertAdjacentHTML('beforeEnd','<span class="uf uf-arrow-up u-grid-header-sort-span" ><span class="u-grid-header-sort-priority">1</span></span>');
$(ele.firstChild.firstChild)[0].insertAdjacentHTML('beforeEnd', '<span class="uf uf-arrow-up u-grid-header-sort-span" ></span>');
if (typeof this.options.onSortFun == 'function') {
this.options.onSortFun(field, 'asc')
this.options.onSortFun.call(this, field, 'asc')
} else {
this.dataSourceObj.sortRows(field, "asc");
}
} else if ($(".uf-arrow-up").parent().parent().parent()[0] == ele) { //原来为降序,本次为不排序
$(".uf-arrow-up").remove();
if (typeof this.options.onSortFun == 'function') {
this.options.onSortFun();
this.options.onSortFun.call(this);
} else {
this.dataSourceObj.sortRows();
}
@@ -107,7 +107,7 @@ const canSortable = function(e, ele) {
// $(ele.firstChild)[0].insertAdjacentHTML('beforeEnd','<span class="uf uf-arrow-down u-grid-header-sort-span"><span class="u-grid-header-sort-priority">1</span></span>');
$(ele.firstChild.firstChild)[0].insertAdjacentHTML('beforeEnd', '<span class="uf uf-arrow-down u-grid-header-sort-span"></span>');
if (typeof this.options.onSortFun == 'function') {
this.options.onSortFun(field, "desc");
this.options.onSortFun.call(this, field, "desc");
} else {
this.dataSourceObj.sortRows(field, "desc");
}
@@ -210,8 +210,10 @@ const swapColumnEnd = function(e) {
this.gridCompColumnArr.splice(parseInt(swapColumnIndex), 1);
else
this.gridCompColumnArr.splice(parseInt(swapColumnIndex) + 1, 1);
this.saveGridCompColumnArrToLocal();
this.repaintGridDivs();
this.resetColumnWidthByRealWidth();
}
$('#' + this.options.id + '_clue').remove();
$('#' + this.options.id + '_swap_top').css('display', 'none');

0 comments on commit 175e98d

Please sign in to comment.