Permalink
Browse files

fix: 修改获取rowIndex的bug

  • Loading branch information...
HuYuee committed Jun 20, 2017
1 parent 21c118f commit 50b5096618183651475bedc30355b787ed7d5204
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -5,30 +5,7 @@ var init = function init(options, gridComp) {
// this.gridComp = gridComp; // 在处理前端缓存将column转为string的时候会因为此属性出现死循环
var gridOptions = gridComp.options;
this.gridGetBoolean = gridComp.getBoolean;
this.defaults = {
width: '200', // 默认宽度为200
sortable: true, // 是否可以排序
canDrag: true, // 是否可以拖动
fixed: false, // 是否固定列
visible: true, // 是否显示
canVisible: true, // 是否可以隐藏
sumCol: false, // 是否计算合计
editable: true, // 是否可修改
editFormShow: true, // 是否可修改
autoExpand: false, // 是否自动扩展列
editType: 'text', // 编辑类型,支持传入function扩展
dataType: 'String', // 数据类型,String, Date, Datetime, Int, Float
//precision: //精度
format: 'YYYY-MM-DD hh:mm:ss',
//renderType:'', 渲染类型
//headerColor
headerLevel: 1, // header层级
hiddenLevel: 1, // 宽度不足隐藏的优先级,值越大优先隐藏
// parentHeader 对应的父header的title
// 目前仅支持两级,多级的话需要改变头的高度,另外处理当前级别的时候需要看下是否存在上级,如果存在上级的话
// 则创建新的div,这就涉及到需要躲变量计算每级的宽度,需要考虑下如何实现。
// headerColor:'#a8a8a8'
textAlign: 'left' };
this.initDefault();
// 从grid继承的属性
var gridDefault = {
sortable: gridOptions.sortable,
@@ -55,6 +32,33 @@ var init = function init(options, gridComp) {
var initTree = function initTree(options) {
return options;
};
var initDefault = function initDefault() {
this.defaults = {
width: '200', // 默认宽度为200
sortable: true, // 是否可以排序
canDrag: true, // 是否可以拖动
fixed: false, // 是否固定列
visible: true, // 是否显示
canVisible: true, // 是否可以隐藏
sumCol: false, // 是否计算合计
editable: true, // 是否可修改
editFormShow: true, // 是否可修改
autoExpand: false, // 是否自动扩展列
editType: 'text', // 编辑类型,支持传入function扩展
dataType: 'String', // 数据类型,String, Date, Datetime, Int, Float
//precision: //精度
format: 'YYYY-MM-DD hh:mm:ss',
//renderType:'', 渲染类型
//headerColor
headerLevel: 1, // header层级
hiddenLevel: 1, // 宽度不足隐藏的优先级,值越大优先隐藏
// parentHeader 对应的父header的title
// 目前仅支持两级,多级的话需要改变头的高度,另外处理当前级别的时候需要看下是否存在上级,如果存在上级的话
// 则创建新的div,这就涉及到需要躲变量计算每级的宽度,需要考虑下如何实现。
// headerColor:'#a8a8a8'
textAlign: 'left' };
};
var getBooleanOptions = function getBooleanOptions() {
this.options.sortable = this.gridGetBoolean(this.options.sortable);
this.options.canDrag = this.gridGetBoolean(this.options.canDrag);
@@ -69,6 +73,7 @@ var getBooleanOptions = function getBooleanOptions() {
export var initFunObj = {
init: init,
initDefault: initDefault,
initTree: initTree,
getBooleanOptions: getBooleanOptions
};
View
@@ -52,7 +52,7 @@ var createGridDivs = function createGridDivs() {
}
// 为避免重复渲染,在开始清空里面内容
if ($('#' + this.options.id)[0]) $('#' + this.options.id)[0].innerHTML = '';
var htmlStr = '<div id="' + this.options.id + '_grid" class="u-grid-grid">';
var htmlStr = '<div id="' + this.options.id + '_grid" class="u-grid">';
htmlStr += this.createHeader();
htmlStr += this.createBeginNoScroll();
htmlStr += this.createContent();
@@ -333,7 +333,11 @@ var createThead = function createThead(createFlag) {
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>';
var requiredHtml = '';
if (this.options.required) {
requiredHtml = '<span style="color:red;">*</span>';
}
htmlStr += '<div class="u-grid-header-link" field="' + this.options.field + '" ' + colorStype + '>' + this.options.title + requiredHtml + '</div>';
/*if(oThis.options.columnMenu && createFlag != 'fixed'){
// 创建右侧按钮图标
htmlStr += '<div class="u-grid-header-columnmenu uf uf-navmenu-light " field="' + this.options.field + '" style="display:none;"></div>';
@@ -378,8 +382,8 @@ var createContent = function createContent() {
} else {
lbw = this.leftW + this.fixedWidth;
}
htmlStr += '<div class="u-grid-content-left-bottom" id="' + this.options.id + '_content_left_bottom" style="width:' + lbw + 'px;' + displayStr + '">';
htmlStr += '</div>';
// htmlStr += '<div class="u-grid-content-left-bottom" id="' + this.options.id + '_content_left_bottom" style="width:' + lbw + 'px;' + displayStr + '">';
// htmlStr += '</div>';
}
htmlStr += this.createContentTableFixed();
htmlStr += this.createContentTable();
@@ -415,7 +419,7 @@ var createContentLeft = function createContentLeft() {
}
}
if (this.options.multiSelect) {
htmlStr += '<div class="u-grid-content-left ' + sumRowClass + '" id="' + this.options.id + '_content_multiSelect" style="width:' + this.multiSelectWidth + 'px;' + hStr + topStr + '">';
htmlStr += '<div class="u-grid-content-left u-grid-content-left-multi ' + sumRowClass + '" id="' + this.options.id + '_content_multiSelect" style="width:' + this.multiSelectWidth + 'px;' + hStr + topStr + '">';
// 遍历生成所有行
if (this.dataSourceObj.rows) {
if (this.options.groupSumRow) {
@@ -430,7 +434,7 @@ var createContentLeft = function createContentLeft() {
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 + topStr + '">';
htmlStr += '<div class="u-grid-content-left u-grid-content-left-num ' + sumRowClass + '" id="' + this.options.id + '_content_numCol" style="width:' + this.numWidth + 'px;left:' + left + 'px;' + hStr + topStr + '">';
// 遍历生成所有行
if (this.dataSourceObj.rows) {
if (this.options.groupSumRow) {
@@ -469,15 +473,20 @@ var createContentLeftMultiSelectRow = function createContentLeftMultiSelectRow(r
var rootObj = row.value;
var objAry = this.selectRows;
var re = objCompare(rootObj, objAry);
var heightStr = '';
if (!this.options.needResetHeight) {
heightStr = 'height:' + (this.options.rowHeight + 1) + 'px;';
}
if (gridBrowser.isIE8) {
//var htmlStr = '<div style="width:' + this.multiSelectWidth + 'px;' + displayStr + '" class="u-grid-content-multiSelect " ><input class="u-grid-multi-input" id="checkbox'+tmpcheck+'" type="checkbox" value="1" ></div>'
var htmlStr = '<div style="width:' + this.multiSelectWidth + 'px;' + displayStr + '" class="u-grid-content-multiSelect " ><span class="u-grid-checkbox-outline" id="checkbox' + tmpcheck + '" value="1"><span class="u-grid-checkbox-tick-outline"></span></span></div>';
var htmlStr = '<div style="width:' + this.multiSelectWidth + 'px;' + heightStr + displayStr + '" class="u-grid-content-multiSelect " ><span class="u-grid-checkbox-outline" id="checkbox' + tmpcheck + '" value="1"><span class="u-grid-checkbox-tick-outline"></span></span></div>';
} else {
if (re) {
var htmlStr = '<div style="width:' + this.multiSelectWidth + 'px;' + displayStr + '" class="u-grid-content-multiSelect checkbox check-success u-grid-content-sel-row" ><span class="u-grid-checkbox-outline is-checked" id="checkbox' + tmpcheck + '" value="1"><span class="u-grid-checkbox-tick-outline"></span></span></div>';
var htmlStr = '<div style="width:' + this.multiSelectWidth + 'px;' + heightStr + displayStr + '" class="u-grid-content-multiSelect checkbox check-success u-grid-content-sel-row" ><span class="u-grid-checkbox-outline is-checked" id="checkbox' + tmpcheck + '" value="1"><span class="u-grid-checkbox-tick-outline"></span></span></div>';
} else {
var htmlStr = '<div style="width:' + this.multiSelectWidth + 'px;' + displayStr + '" class="u-grid-content-multiSelect checkbox check-success" ><span class="u-grid-checkbox-outline" id="checkbox' + tmpcheck + '" value="1"><span class="u-grid-checkbox-tick-outline"></span></span></div>';
var htmlStr = '<div style="width:' + this.multiSelectWidth + 'px;' + heightStr + displayStr + '" class="u-grid-content-multiSelect checkbox check-success" ><span class="u-grid-checkbox-outline" id="checkbox' + tmpcheck + '" value="1"><span class="u-grid-checkbox-tick-outline"></span></span></div>';
}
//var htmlStr = '<div style="width:' + this.multiSelectWidth + 'px;' + displayStr + '" class="u-grid-content-multiSelect checkbox check-success" ><input class="u-grid-multi-input" id="checkbox'+tmpcheck+'" type="checkbox" value="1" ><label for="checkbox'+tmpcheck+'"></label></div>'
}
@@ -492,10 +501,15 @@ var createContentLeftNumColRow = function createContentLeftNumColRow(index) {
var objAry = this.selectRows;
var re = objCompare(rootObj, objAry);
var htmlStr;
var heightStr = '';
if (!this.options.needResetHeight) {
heightStr = 'height:' + (this.options.rowHeight + 1) + 'px;';
}
if (re) {
htmlStr = '<div style="width:' + this.numWidth + 'px;" class="u-grid-content-num u-grid-content-sel-row">' + (index + 1) + '</div>';
htmlStr = '<div style="width:' + this.numWidth + 'px;' + heightStr + '" class="u-grid-content-num u-grid-content-sel-row">' + (index + 1) + '</div>';
} else {
htmlStr = '<div style="width:' + this.numWidth + 'px;" class="u-grid-content-num">' + (index + 1) + '</div>';
htmlStr = '<div style="width:' + this.numWidth + 'px;' + heightStr + '" class="u-grid-content-num">' + (index + 1) + '</div>';
}
return htmlStr;
};
@@ -738,11 +752,14 @@ var createContentOneRowTd = function createContentOneRowTd(row, createFlag) {
var iconStr = '';
var vStr = '';
var tdStyle = '';
var cssStr = '';
var classStr = '';
var rowHeight = oThis.options.rowHeight;
if (oThis.options.showTree && this.firstColumn) {
var l = parseInt(oThis.treeLeft) * parseInt(row.level);
treeStyle = 'style="position:relative;';
if (row.hasChild) {
if (oThis.options.autoExpand) {
if (row.hasChild || value.isParent) {
if (oThis.options.autoExpand && !value.isParent) {
spanStr = '<span class=" uf uf-reduce-s-o u-grid-content-tree-span"></span>';
} else {
spanStr = '<span class=" uf uf-add-s-o u-grid-content-tree-span"></span>';
@@ -751,28 +768,55 @@ var createContentOneRowTd = function createContentOneRowTd(row, createFlag) {
l += 16;
}
treeStyle += 'text-align:' + this.options.textAlign + ';';
if (oThis.options.maxHeight > 40) {
treeStyle += 'max-height:' + oThis.options.maxHeight + 'px;';
}
treeStyle += 'left:' + l + 'px;"';
} else {
treeStyle += 'style="text-align:' + this.options.textAlign + '";';
if (oThis.options.maxHeight > 40) {
treeStyle += 'style="text-align:' + this.options.textAlign + ';max-height:' + oThis.options.maxHeight + 'px;"';
} else {
treeStyle += 'style="text-align:' + this.options.textAlign + ';"';
}
}
if (this.options.icon) {
iconStr = '<span class="' + this.options.icon + '"></span>';
}
if (oThis.options.heightAuto) {
cssStr = 'height-auto';
}
// title="' + v + '" 创建td的时候不在设置title,在renderType中设置,处理现实xml的情况
if (oThis.options.groupField && f == oThis.options.groupField) {
classStr = 'class="u-grid-content-td-group-field';
if (oThis.nowGroupValue == v) {
classStr += ' no-text';
oThis.nowGroupIndex++;
} else {
oThis.nowGroupIndex = 1;
oThis.nowGroupValue = v;
oThis.nowGroupRow = oThis.getGroupRowByGroupValue(v);
oThis.nowGroupRowCount = oThis.nowGroupRow.rows.length;
}
if (oThis.nowGroupIndex == oThis.nowGroupRowCount) {
classStr += ' group-last';
}
classStr += '"';
if (oThis.nowGroupIndex == 1) rowHeight = oThis.options.rowHeight * oThis.nowGroupRowCount;
}
if (!this.options.visible) {
tdStyle = 'style="display:none;';
if (oThis.options.rowHeight) {
tdStyle += 'height:' + oThis.options.rowHeight + 'px;line-height:' + oThis.options.rowHeight + 'px;';
tdStyle += 'height:' + oThis.options.rowHeight + 'px;line-height:' + rowHeight + 'px;';
}
tdStyle += '"';
} else {
if (oThis.options.rowHeight) {
tdStyle += 'style="height:' + oThis.options.rowHeight + 'px;line-height:' + oThis.options.rowHeight + 'px;"';
tdStyle += 'style="height:' + oThis.options.rowHeight + 'px;line-height:' + rowHeight + 'px;"';
}
}
if (this.options.icon) {
iconStr = '<span class="' + this.options.icon + '"></span>';
}
// title="' + v + '" 创建td的时候不在设置title,在renderType中设置,处理现实xml的情况
htmlStr += '<td role="rowcell" ' + tdStyle + ' ><div class="u-grid-content-td-div" ' + treeStyle + '>' + spanStr + iconStr + '<span>' + v.replace(/\</g, '&lt;').replace(/\>/g, '&gt;') + '</span></div></td>';
htmlStr += '<td role="rowcell" ' + tdStyle + classStr + ' realValue="' + v + '" ><div class="u-grid-content-td-div ' + cssStr + '" ' + treeStyle + '>' + spanStr + iconStr + '<span>' + v.replace(/\</g, '&lt;').replace(/\>/g, '&gt;') + '</span></div></td>';
});
return htmlStr;
};
@@ -801,22 +845,33 @@ var createContentOneRowTdForIE = function createContentOneRowTdForIE(row, rowObj
iconStr = '',
vStr = '',
htmlStr = '',
newCell = row.insertCell();
newCell = row.insertCell(),
cssStr = '';
newCell.setAttribute("role", "rowcell");
// newCell.title = v.replace(/\</g,'\<').replace(/\>/g,'\>');
if (oThis.options.showTree && this.firstColumn) {
var l = parseInt(oThis.treeLeft) * parseInt(rowObj.level);
var l = parseInt(oThis.treeLeft) * parseInt(row.level);
treeStyle = 'style="position:relative;';
if (rowObj.hasChild) {
if (oThis.options.autoExpand) {
if (row.hasChild || value.isParent) {
if (oThis.options.autoExpand && !value.isParent) {
spanStr = '<span class=" uf uf-reduce-s-o u-grid-content-tree-span"></span>';
} else {
spanStr = '<span class=" uf uf-add-s-o u-grid-content-tree-span"></span>';
}
} else {
l += 18;
l += 16;
}
treeStyle += 'text-align:' + this.options.textAlign + ';';
if (oThis.options.maxHeight > 40) {
treeStyle += 'max-height:' + oThis.options.maxHeight + 'px;';
}
treeStyle += 'left:' + l + 'px;"';
} else {
if (oThis.options.maxHeight > 40) {
treeStyle += 'style="text-align:' + this.options.textAlign + ';max-height:' + oThis.options.maxHeight + 'px;"';
} else {
treeStyle += 'style="text-align:' + this.options.textAlign + ';"';
}
}
if (!this.options.visible) {
newCell.style.display = "none";
@@ -828,7 +883,10 @@ var createContentOneRowTdForIE = function createContentOneRowTdForIE(row, rowObj
if (this.options.icon) {
iconStr = '<span class="' + this.options.icon + '"></span>';
}
htmlStr += '<div class="u-grid-content-td-div" ' + treeStyle + '>' + spanStr + iconStr + '<span>' + v.replace(/\</g, '&lt;').replace(/\>/g, '&gt;') + '</span></div>';
if (oThis.options.heightAuto) {
cssStr = 'height-auto';
}
htmlStr += '<div class="u-grid-content-td-div ' + cssStr + '" ' + treeStyle + '>' + spanStr + iconStr + '<span>' + v.replace(/\</g, '&lt;').replace(/\>/g, '&gt;') + '</span></div>';
newCell.insertAdjacentHTML('afterBegin', htmlStr);
});
};
View
@@ -65,6 +65,9 @@ var countRowHeight = function countRowHeight() {
* 根据内容区的高度调整左侧区域的高度
*/
var resetLeftHeight = function resetLeftHeight() {
if (!this.options.needResetHeight) {
return;
}
var self = this;
if (this.resetLeftHeightSetTimeout) clearTimeout(this.resetLeftHeightSetTimeout);
this.resetLeftHeightSetTimeout = setTimeout(function () {
@@ -81,12 +84,13 @@ var resetLeftHeightFun = function resetLeftHeightFun() {
var nowRowHeight = $trs[i].offsetHeight;
if ($leftNums[i]) {
$leftNums[i].style.height = nowRowHeight + 'px';
// $leftNums[i].style.lineHeight = nowRowHeight + 'px';
$leftNums[i].style.lineHeight = nowRowHeight + 'px';
}
if ($leftSelects[i]) {
$leftSelects[i].style.height = nowRowHeight + 'px';
// $leftSelects[i].style.lineHeight = nowRowHeight + 'px';
$leftSelects[i].style.lineHeight = nowRowHeight + 'px';
$($leftSelects[i]).find('.u-grid-checkbox-outline').css('top', (nowRowHeight - 14) / 2);
}
}
}
View
@@ -140,7 +140,8 @@ var getRowByIndex = function getRowByIndex(index) {
var getRowIndexByValue = function getRowIndexByValue(field, value) {
var index = -1;
$.each(this.dataSourceObj.rows, function (i) {
var v = $(this.value).attr(field);
// var v = $(this.value).attr(field);
var v = this.value[field];
if (v == value) {
index = i;
}
Oops, something went wrong.

0 comments on commit 50b5096

Please sign in to comment.