|
|
@ -85,6 +85,7 @@ layui.define(['table'], function (exports) {
|
|
|
|
var LAY_DATA_INDEX = 'LAY_DATA_INDEX';
|
|
|
|
var LAY_DATA_INDEX = 'LAY_DATA_INDEX';
|
|
|
|
var LAY_DATA_INDEX_HISTORY = 'LAY_DATA_INDEX_HISTORY';
|
|
|
|
var LAY_DATA_INDEX_HISTORY = 'LAY_DATA_INDEX_HISTORY';
|
|
|
|
var LAY_PARENT_INDEX = 'LAY_PARENT_INDEX';
|
|
|
|
var LAY_PARENT_INDEX = 'LAY_PARENT_INDEX';
|
|
|
|
|
|
|
|
var LAY_CHECKBOX_HALF = 'LAY_CHECKBOX_HALF';
|
|
|
|
|
|
|
|
|
|
|
|
// 构造器
|
|
|
|
// 构造器
|
|
|
|
var Class = function (options) {
|
|
|
|
var Class = function (options) {
|
|
|
@ -149,6 +150,17 @@ layui.define(['table'], function (exports) {
|
|
|
|
that.initData(options.data);
|
|
|
|
that.initData(options.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var updateCache = function (data) {
|
|
|
|
|
|
|
|
var tableCache = table.cache[id];
|
|
|
|
|
|
|
|
layui.each(data || tableCache, function (index, item) {
|
|
|
|
|
|
|
|
var itemDataIndex = item[LAY_DATA_INDEX];
|
|
|
|
|
|
|
|
if (itemDataIndex.indexOf('-') !== -1) {
|
|
|
|
|
|
|
|
tableCache[itemDataIndex] = item
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
item[childrenKey] && updateCache(item[childrenKey]);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
options.done = function () {
|
|
|
|
options.done = function () {
|
|
|
|
var args = arguments;
|
|
|
|
var args = arguments;
|
|
|
|
var doneThat = this;
|
|
|
|
var doneThat = this;
|
|
|
@ -156,7 +168,10 @@ layui.define(['table'], function (exports) {
|
|
|
|
var tableView = this.elem.next();
|
|
|
|
var tableView = this.elem.next();
|
|
|
|
that.updateStatus(null, {
|
|
|
|
that.updateStatus(null, {
|
|
|
|
LAY_HAS_EXPANDED: false // 去除已经打开过的状态
|
|
|
|
LAY_HAS_EXPANDED: false // 去除已经打开过的状态
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
// 更新cache中的内容 将子节点也存到cache中
|
|
|
|
|
|
|
|
updateCache();
|
|
|
|
|
|
|
|
|
|
|
|
that.renderTreeTable(tableView);
|
|
|
|
that.renderTreeTable(tableView);
|
|
|
|
|
|
|
|
|
|
|
|
if (layui.type(done) === 'function') {
|
|
|
|
if (layui.type(done) === 'function') {
|
|
|
@ -349,7 +364,6 @@ layui.define(['table'], function (exports) {
|
|
|
|
item1[LAY_DATA_INDEX_HISTORY] = item1[LAY_DATA_INDEX];
|
|
|
|
item1[LAY_DATA_INDEX_HISTORY] = item1[LAY_DATA_INDEX];
|
|
|
|
item1[LAY_PARENT_INDEX] = parentIndex = parentIndex || '';
|
|
|
|
item1[LAY_PARENT_INDEX] = parentIndex = parentIndex || '';
|
|
|
|
var dataIndex = item1[LAY_DATA_INDEX] = (parentIndex ? parentIndex + '-' : '') + i1;
|
|
|
|
var dataIndex = item1[LAY_DATA_INDEX] = (parentIndex ? parentIndex + '-' : '') + i1;
|
|
|
|
dataIndex.indexOf('-') !== -1 && (table.cache[tableId][dataIndex] = item1);
|
|
|
|
|
|
|
|
that.initData(item1[childrenKey] || [], dataIndex);
|
|
|
|
that.initData(item1[childrenKey] || [], dataIndex);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -365,7 +379,7 @@ layui.define(['table'], function (exports) {
|
|
|
|
var options = table.getOptions(tableId);
|
|
|
|
var options = table.getOptions(tableId);
|
|
|
|
var treeOptions = options.tree || {};
|
|
|
|
var treeOptions = options.tree || {};
|
|
|
|
var isParentKey = treeOptions.data.key.isParent;
|
|
|
|
var isParentKey = treeOptions.data.key.isParent;
|
|
|
|
var trIndex = trElem.attr('data-index'); // 可能出现多层
|
|
|
|
var trIndex = trElem.attr('lay-data-index'); // 可能出现多层
|
|
|
|
var treeTableThat = getThisTable(tableId);
|
|
|
|
var treeTableThat = getThisTable(tableId);
|
|
|
|
var tableData = treeTableThat.getTableData();
|
|
|
|
var tableData = treeTableThat.getTableData();
|
|
|
|
|
|
|
|
|
|
|
@ -391,8 +405,8 @@ layui.define(['table'], function (exports) {
|
|
|
|
|
|
|
|
|
|
|
|
var LAY_HAS_EXPANDED = trData['LAY_HAS_EXPANDED']; // 展开过,包括异步加载
|
|
|
|
var LAY_HAS_EXPANDED = trData['LAY_HAS_EXPANDED']; // 展开过,包括异步加载
|
|
|
|
|
|
|
|
|
|
|
|
// 找到表格中的同类节点(需要找到data-index一致的所有行)
|
|
|
|
// 找到表格中的同类节点(需要找到lay-data-index一致的所有行)
|
|
|
|
var trsElem = tableViewElem.find('tr[data-index="' + trIndex + '"]');
|
|
|
|
var trsElem = tableViewElem.find('tr[lay-data-index="' + trIndex + '"]');
|
|
|
|
// 处理折叠按钮图标
|
|
|
|
// 处理折叠按钮图标
|
|
|
|
var flexIconElem = trsElem.find('.layui-table-tree-flexIcon');
|
|
|
|
var flexIconElem = trsElem.find('.layui-table-tree-flexIcon');
|
|
|
|
flexIconElem.html(LAY_EXPAND ? treeOptions.view.flexIconOpen : treeOptions.view.flexIconClose)
|
|
|
|
flexIconElem.html(LAY_EXPAND ? treeOptions.view.flexIconOpen : treeOptions.view.flexIconClose)
|
|
|
@ -413,15 +427,15 @@ layui.define(['table'], function (exports) {
|
|
|
|
trData['LAY_EXPAND'] = LAY_EXPAND;
|
|
|
|
trData['LAY_EXPAND'] = LAY_EXPAND;
|
|
|
|
|
|
|
|
|
|
|
|
tableViewElem.find(childNodes.map(function (value, index, array) {
|
|
|
|
tableViewElem.find(childNodes.map(function (value, index, array) {
|
|
|
|
return 'tr[data-index="' + value[LAY_DATA_INDEX] + '"]'
|
|
|
|
return 'tr[lay-data-index="' + value[LAY_DATA_INDEX] + '"]'
|
|
|
|
}).join(',')).removeClass('layui-hide');
|
|
|
|
}).join(',')).removeClass('layui-hide');
|
|
|
|
layui.each(childNodes, function (i1, item1) {
|
|
|
|
layui.each(childNodes, function (i1, item1) {
|
|
|
|
if (sonSign && !isToggle) { // 非状态切换的情况下
|
|
|
|
if (sonSign && !isToggle) { // 非状态切换的情况下
|
|
|
|
// 级联展开子节点
|
|
|
|
// 级联展开子节点
|
|
|
|
expandNode({trElem: tableViewElem.find('tr[data-index="' + item1.LAY_DATA_INDEX + '"]').first()}, expandFlag, sonSign, focus, callbackFlag);
|
|
|
|
expandNode({trElem: tableViewElem.find('tr[lay-data-index="' + item1.LAY_DATA_INDEX + '"]').first()}, expandFlag, sonSign, focus, callbackFlag);
|
|
|
|
} else if (item1.LAY_EXPAND) {
|
|
|
|
} else if (item1.LAY_EXPAND) {
|
|
|
|
// 级联展开
|
|
|
|
// 级联展开
|
|
|
|
expandNode({trElem: tableViewElem.find('tr[data-index="' + item1.LAY_DATA_INDEX + '"]').first()}, true);
|
|
|
|
expandNode({trElem: tableViewElem.find('tr[lay-data-index="' + item1.LAY_DATA_INDEX + '"]').first()}, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -511,20 +525,26 @@ layui.define(['table'], function (exports) {
|
|
|
|
trs_fixed_r: $(str2.trs_fixed_r.join(''))
|
|
|
|
trs_fixed_r: $(str2.trs_fixed_r.join(''))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
layui.each(childNodes, function (childIndex, childItem) {
|
|
|
|
layui.each(childNodes, function (childIndex, childItem) {
|
|
|
|
str2Obj.trs.eq(childIndex).attr({'data-index': childItem[LAY_DATA_INDEX], 'data-level': dataLevelNew})
|
|
|
|
str2Obj.trs.eq(childIndex).attr({
|
|
|
|
|
|
|
|
'data-index': childItem[LAY_DATA_INDEX],
|
|
|
|
|
|
|
|
'lay-data-index': childItem[LAY_DATA_INDEX],
|
|
|
|
|
|
|
|
'data-level': dataLevelNew
|
|
|
|
|
|
|
|
})
|
|
|
|
str2Obj.trs_fixed.eq(childIndex).attr({
|
|
|
|
str2Obj.trs_fixed.eq(childIndex).attr({
|
|
|
|
'data-index': childItem[LAY_DATA_INDEX],
|
|
|
|
'data-index': childItem[LAY_DATA_INDEX],
|
|
|
|
|
|
|
|
'lay-data-index': childItem[LAY_DATA_INDEX],
|
|
|
|
'data-level': dataLevelNew
|
|
|
|
'data-level': dataLevelNew
|
|
|
|
})
|
|
|
|
})
|
|
|
|
str2Obj.trs_fixed_r.eq(childIndex).attr({
|
|
|
|
str2Obj.trs_fixed_r.eq(childIndex).attr({
|
|
|
|
'data-index': childItem[LAY_DATA_INDEX],
|
|
|
|
'data-index': childItem[LAY_DATA_INDEX],
|
|
|
|
|
|
|
|
'lay-data-index': childItem[LAY_DATA_INDEX],
|
|
|
|
'data-level': dataLevelNew
|
|
|
|
'data-level': dataLevelNew
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
tableViewElem.find(ELEM_MAIN).find('tbody tr[data-index="' + trIndex + '"]').after(str2Obj.trs);
|
|
|
|
tableViewElem.find(ELEM_MAIN).find('tbody tr[lay-data-index="' + trIndex + '"]').after(str2Obj.trs);
|
|
|
|
tableViewElem.find(ELEM_FIXL).find('tbody tr[data-index="' + trIndex + '"]').after(str2Obj.trs_fixed);
|
|
|
|
tableViewElem.find(ELEM_FIXL).find('tbody tr[lay-data-index="' + trIndex + '"]').after(str2Obj.trs_fixed);
|
|
|
|
tableViewElem.find(ELEM_FIXR).find('tbody tr[data-index="' + trIndex + '"]').after(str2Obj.trs_fixed_r);
|
|
|
|
tableViewElem.find(ELEM_FIXR).find('tbody tr[lay-data-index="' + trIndex + '"]').after(str2Obj.trs_fixed_r);
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化新增的节点中的内容
|
|
|
|
// 初始化新增的节点中的内容
|
|
|
|
layui.each(str2Obj, function (key, item) {
|
|
|
|
layui.each(str2Obj, function (key, item) {
|
|
|
@ -534,7 +554,7 @@ layui.define(['table'], function (exports) {
|
|
|
|
if (sonSign && !isToggle) { // 非状态切换的情况下
|
|
|
|
if (sonSign && !isToggle) { // 非状态切换的情况下
|
|
|
|
// 级联展开/关闭子节点
|
|
|
|
// 级联展开/关闭子节点
|
|
|
|
layui.each(childNodes, function (i1, item1) {
|
|
|
|
layui.each(childNodes, function (i1, item1) {
|
|
|
|
expandNode({trElem: tableViewElem.find('tr[data-index="' + item1.LAY_DATA_INDEX + '"]').first()}, expandFlag, sonSign, focus, callbackFlag);
|
|
|
|
expandNode({trElem: tableViewElem.find('tr[lay-data-index="' + item1.LAY_DATA_INDEX + '"]').first()}, expandFlag, sonSign, focus, callbackFlag);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -546,15 +566,15 @@ layui.define(['table'], function (exports) {
|
|
|
|
// 折叠
|
|
|
|
// 折叠
|
|
|
|
if (sonSign && !isToggle) { // 非状态切换的情况下
|
|
|
|
if (sonSign && !isToggle) { // 非状态切换的情况下
|
|
|
|
layui.each(childNodes, function (i1, item1) {
|
|
|
|
layui.each(childNodes, function (i1, item1) {
|
|
|
|
expandNode({trElem: tableViewElem.find('tr[data-index="' + item1.LAY_DATA_INDEX + '"]').first()}, expandFlag, sonSign, focus, callbackFlag);
|
|
|
|
expandNode({trElem: tableViewElem.find('tr[lay-data-index="' + item1.LAY_DATA_INDEX + '"]').first()}, expandFlag, sonSign, focus, callbackFlag);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
tableViewElem.find(childNodes.map(function (value, index, array) { // 只隐藏直接子节点,其他由递归的处理
|
|
|
|
tableViewElem.find(childNodes.map(function (value, index, array) { // 只隐藏直接子节点,其他由递归的处理
|
|
|
|
return 'tr[data-index="' + value[LAY_DATA_INDEX] + '"]'
|
|
|
|
return 'tr[lay-data-index="' + value[LAY_DATA_INDEX] + '"]'
|
|
|
|
}).join(',')).addClass('layui-hide');
|
|
|
|
}).join(',')).addClass('layui-hide');
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
var childNodesFlat = treeTableThat.treeToFlat(childNodes, trData[treeOptions.data.simpleData.idKey], trIndex);
|
|
|
|
var childNodesFlat = treeTableThat.treeToFlat(childNodes, trData[treeOptions.data.simpleData.idKey], trIndex);
|
|
|
|
tableViewElem.find(childNodesFlat.map(function (value, index, array) {
|
|
|
|
tableViewElem.find(childNodesFlat.map(function (value, index, array) {
|
|
|
|
return 'tr[data-index="' + value[LAY_DATA_INDEX] + '"]'
|
|
|
|
return 'tr[lay-data-index="' + value[LAY_DATA_INDEX] + '"]'
|
|
|
|
}).join(',')).addClass('layui-hide');
|
|
|
|
}).join(',')).addClass('layui-hide');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -573,7 +593,7 @@ layui.define(['table'], function (exports) {
|
|
|
|
var that = getThisTable(id);
|
|
|
|
var that = getThisTable(id);
|
|
|
|
var options = that.getOptions();
|
|
|
|
var options = that.getOptions();
|
|
|
|
var tableViewElem = options.elem.next();
|
|
|
|
var tableViewElem = options.elem.next();
|
|
|
|
return expandNode({trElem: tableViewElem.find('tr[data-index="' + index + '"]').first()}, expandFlag, sonSign, null, callbackFlag)
|
|
|
|
return expandNode({trElem: tableViewElem.find('tr[lay-data-index="' + index + '"]').first()}, expandFlag, sonSign, null, callbackFlag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 目前还有性能问题特别是在data模式需要优化暂时不能使用 todo
|
|
|
|
// 目前还有性能问题特别是在data模式需要优化暂时不能使用 todo
|
|
|
@ -606,9 +626,9 @@ layui.define(['table'], function (exports) {
|
|
|
|
// 初始化的表格里面没有level信息,可以作为顶层节点的判断
|
|
|
|
// 初始化的表格里面没有level信息,可以作为顶层节点的判断
|
|
|
|
tableViewElem.find('.layui-table-body tr:not([data-level])').attr('data-level', level);
|
|
|
|
tableViewElem.find('.layui-table-body tr:not([data-level])').attr('data-level', level);
|
|
|
|
layui.each(table.cache[tableId], function (dataIndex, dataItem) {
|
|
|
|
layui.each(table.cache[tableId], function (dataIndex, dataItem) {
|
|
|
|
tableViewElem.find('.layui-table-main tbody tr[data-level="0"]:eq(' + dataIndex + ')').attr('data-index', dataItem[LAY_DATA_INDEX]);
|
|
|
|
tableViewElem.find('.layui-table-main tbody tr[data-level="0"]:eq(' + dataIndex + ')').attr('lay-data-index', dataItem[LAY_DATA_INDEX]);
|
|
|
|
tableViewElem.find('.layui-table-fixed-l tbody tr[data-level="0"]:eq(' + dataIndex + ')').attr('data-index', dataItem[LAY_DATA_INDEX]);
|
|
|
|
tableViewElem.find('.layui-table-fixed-l tbody tr[data-level="0"]:eq(' + dataIndex + ')').attr('lay-data-index', dataItem[LAY_DATA_INDEX]);
|
|
|
|
tableViewElem.find('.layui-table-fixed-r tbody tr[data-level="0"]:eq(' + dataIndex + ')').attr('data-index', dataItem[LAY_DATA_INDEX]);
|
|
|
|
tableViewElem.find('.layui-table-fixed-r tbody tr[data-level="0"]:eq(' + dataIndex + ')').attr('lay-data-index', dataItem[LAY_DATA_INDEX]);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -624,7 +644,7 @@ layui.define(['table'], function (exports) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
itemCell.addClass('layui-table-tree-item');
|
|
|
|
itemCell.addClass('layui-table-tree-item');
|
|
|
|
var trIndex = trElem.attr('data-index');
|
|
|
|
var trIndex = trElem.attr('lay-data-index');
|
|
|
|
if (!trIndex) { // 排除在统计行中的节点
|
|
|
|
if (!trIndex) { // 排除在统计行中的节点
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -662,7 +682,7 @@ layui.define(['table'], function (exports) {
|
|
|
|
|
|
|
|
|
|
|
|
// 当前层的数据看看是否需要展开
|
|
|
|
// 当前层的数据看看是否需要展开
|
|
|
|
sonSign !== false && layui.each(dataExpand, function (index, item) {
|
|
|
|
sonSign !== false && layui.each(dataExpand, function (index, item) {
|
|
|
|
var trDefaultExpand = tableViewElem.find('tr[data-index="' + index + '"]');
|
|
|
|
var trDefaultExpand = tableViewElem.find('tr[lay-data-index="' + index + '"]');
|
|
|
|
trDefaultExpand.find('.layui-table-tree-flexIcon').html(treeOptions.view.flexIconOpen);
|
|
|
|
trDefaultExpand.find('.layui-table-tree-flexIcon').html(treeOptions.view.flexIconOpen);
|
|
|
|
expandNode({trElem: trDefaultExpand.first()}, true);
|
|
|
|
expandNode({trElem: trDefaultExpand.first()}, true);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -689,7 +709,7 @@ layui.define(['table'], function (exports) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var itemData = that.getNodeDataByIndex(item1.LAY_DATA_INDEX);
|
|
|
|
var itemData = that.getNodeDataByIndex(item1.LAY_DATA_INDEX);
|
|
|
|
itemData['LAY_NUM'] = ++num;
|
|
|
|
itemData['LAY_NUM'] = ++num;
|
|
|
|
tableViewElem.find('tr[data-index="' + item1.LAY_DATA_INDEX + '"] .laytable-cell-numbers').html(itemData['LAY_NUM']);
|
|
|
|
tableViewElem.find('tr[lay-data-index="' + item1.LAY_DATA_INDEX + '"] .laytable-cell-numbers').html(itemData['LAY_NUM']);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
return treeTable;
|
|
|
|
return treeTable;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -826,7 +846,9 @@ layui.define(['table'], function (exports) {
|
|
|
|
var options = that.getOptions();
|
|
|
|
var options = that.getOptions();
|
|
|
|
var treeOptions = options.tree;
|
|
|
|
var treeOptions = options.tree;
|
|
|
|
var tableView = options.elem.next();
|
|
|
|
var tableView = options.elem.next();
|
|
|
|
var trLevel = tableView.find('tr[data-index="' + index + '"]').attr('data-level')
|
|
|
|
var trElem = tableView.find('tr[lay-data-index="' + index + '"]');
|
|
|
|
|
|
|
|
var trIndex = trElem.attr('data-index');
|
|
|
|
|
|
|
|
var trLevel = trElem.attr('data-level')
|
|
|
|
|
|
|
|
|
|
|
|
if (!newNode) {
|
|
|
|
if (!newNode) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -835,11 +857,15 @@ layui.define(['table'], function (exports) {
|
|
|
|
var newNodeTemp = that.getNodeDataByIndex(index, false, newNode);
|
|
|
|
var newNodeTemp = that.getNodeDataByIndex(index, false, newNode);
|
|
|
|
// 获取新的tr替换
|
|
|
|
// 获取新的tr替换
|
|
|
|
var trNew = table.getTrHtml(id, [newNodeTemp]);
|
|
|
|
var trNew = table.getTrHtml(id, [newNodeTemp]);
|
|
|
|
|
|
|
|
debugger;
|
|
|
|
// 重新渲染tr
|
|
|
|
// 重新渲染tr
|
|
|
|
layui.each(['main', 'fixed-l', 'fixed-r'], function (i, item) {
|
|
|
|
layui.each(['main', 'fixed-l', 'fixed-r'], function (i, item) {
|
|
|
|
tableView.find('.layui-table-' + item + ' tbody tr[data-index="' + index + '"]').replaceWith($(trNew[['trs', 'trs_fixed', 'trs_fixed_r'][i]].join('')).attr('data-index', index));
|
|
|
|
tableView.find('.layui-table-' + item + ' tbody tr[lay-data-index="' + index + '"]').replaceWith($(trNew[['trs', 'trs_fixed', 'trs_fixed_r'][i]].join('')).attr({
|
|
|
|
|
|
|
|
'data-index': trIndex,
|
|
|
|
|
|
|
|
'lay-data-index': index,
|
|
|
|
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
that.renderTreeTable(tableView.find('tr[data-index="' + index + '"]'), trLevel);
|
|
|
|
that.renderTreeTable(tableView.find('tr[lay-data-index="' + index + '"]'), trLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 删除数据
|
|
|
|
// 删除数据
|
|
|
@ -857,20 +883,27 @@ layui.define(['table'], function (exports) {
|
|
|
|
delNode = that.getNodeDataByIndex(indexValue, false, 'delete');
|
|
|
|
delNode = that.getNodeDataByIndex(indexValue, false, 'delete');
|
|
|
|
var delNodesFlat = that.treeToFlat([delNode], delNode[treeOptions.data.simpleData.pIdKey], delNode[LAY_PARENT_INDEX]);
|
|
|
|
var delNodesFlat = that.treeToFlat([delNode], delNode[treeOptions.data.simpleData.pIdKey], delNode[LAY_PARENT_INDEX]);
|
|
|
|
layui.each(delNodesFlat, function (i2, item2) {
|
|
|
|
layui.each(delNodesFlat, function (i2, item2) {
|
|
|
|
indexArr.push('tr[data-index="' + item2[LAY_DATA_INDEX] + '"]');
|
|
|
|
indexArr.push('tr[lay-data-index="' + item2[LAY_DATA_INDEX] + '"]');
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
tableView.find(indexArr.join(',')).remove(); // 删除行
|
|
|
|
tableView.find(indexArr.join(',')).remove(); // 删除行
|
|
|
|
// 重新整理数据
|
|
|
|
// 重新整理数据
|
|
|
|
var tableData = that.initData();
|
|
|
|
var tableData = that.initData();
|
|
|
|
// index发生变化需要更新页面tr中对应的data-index 新增和删除都要注意数据结构变动之后的index问题
|
|
|
|
// index发生变化需要更新页面tr中对应的lay-data-index 新增和删除都要注意数据结构变动之后的index问题
|
|
|
|
layui.each(that.treeToFlat(tableData), function (i3, item3) {
|
|
|
|
layui.each(that.treeToFlat(tableData), function (i3, item3) {
|
|
|
|
if (item3[LAY_DATA_INDEX_HISTORY] && item3[LAY_DATA_INDEX_HISTORY] !== item3[LAY_DATA_INDEX]) {
|
|
|
|
if (item3[LAY_DATA_INDEX_HISTORY] && item3[LAY_DATA_INDEX_HISTORY] !== item3[LAY_DATA_INDEX]) {
|
|
|
|
tableView.find('tr[data-index="' + item3[LAY_DATA_INDEX_HISTORY] + '"]').attr('data-index', item3[LAY_DATA_INDEX]);
|
|
|
|
tableView.find('tr[lay-data-index="' + item3[LAY_DATA_INDEX_HISTORY] + '"]').attr({
|
|
|
|
item3[LAY_DATA_INDEX_HISTORY] = item3[LAY_DATA_INDEX];
|
|
|
|
'data-index': item3[LAY_DATA_INDEX],
|
|
|
|
|
|
|
|
'lay-data-index': item3[LAY_DATA_INDEX],
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// item3[LAY_DATA_INDEX_HISTORY] = item3[LAY_DATA_INDEX]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// 重新更新顶层节点的data-index;
|
|
|
|
|
|
|
|
layui.each(table.cache[id], function (i4, item4) {
|
|
|
|
|
|
|
|
tableView.find('tr[data-level="0"][lay-data-index="' + item4[LAY_DATA_INDEX] + '"]').attr('data-index', i4);
|
|
|
|
|
|
|
|
})
|
|
|
|
treeTable.formatNumber(id);
|
|
|
|
treeTable.formatNumber(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -920,13 +953,19 @@ layui.define(['table'], function (exports) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
layui.each(newNodes, function (newNodeIndex, newNodeItem) {
|
|
|
|
layui.each(newNodes, function (newNodeIndex, newNodeItem) {
|
|
|
|
newNodesHtmlObj.trs.eq(newNodeIndex).attr({'data-index': newNodeItem[LAY_DATA_INDEX], 'data-level': '0'})
|
|
|
|
newNodesHtmlObj.trs.eq(newNodeIndex).attr({
|
|
|
|
|
|
|
|
'data-index': newNodeItem[LAY_DATA_INDEX],
|
|
|
|
|
|
|
|
'lay-data-index': newNodeItem[LAY_DATA_INDEX],
|
|
|
|
|
|
|
|
'data-level': '0'
|
|
|
|
|
|
|
|
})
|
|
|
|
newNodesHtmlObj.trs_fixed.eq(newNodeIndex).attr({
|
|
|
|
newNodesHtmlObj.trs_fixed.eq(newNodeIndex).attr({
|
|
|
|
'data-index': newNodeItem[LAY_DATA_INDEX],
|
|
|
|
'data-index': newNodeItem[LAY_DATA_INDEX],
|
|
|
|
|
|
|
|
'lay-data-index': newNodeItem[LAY_DATA_INDEX],
|
|
|
|
'data-level': '0'
|
|
|
|
'data-level': '0'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
newNodesHtmlObj.trs_fixed_r.eq(newNodeIndex).attr({
|
|
|
|
newNodesHtmlObj.trs_fixed_r.eq(newNodeIndex).attr({
|
|
|
|
'data-index': newNodeItem[LAY_DATA_INDEX],
|
|
|
|
'data-index': newNodeItem[LAY_DATA_INDEX],
|
|
|
|
|
|
|
|
'lay-data-index': newNodeItem[LAY_DATA_INDEX],
|
|
|
|
'data-level': '0'
|
|
|
|
'data-level': '0'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -954,14 +993,13 @@ layui.define(['table'], function (exports) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新编号
|
|
|
|
// 重新更新顶层节点的data-index;
|
|
|
|
// layui.each(tableData, function (i1, item1) {
|
|
|
|
layui.each(table.cache[id], function (i4, item4) {
|
|
|
|
// tableViewElemMAIN.find('tr[data-level="0"]').eq(i1).attr('data-index', item1[LAY_DATA_INDEX]);
|
|
|
|
tableViewElem.find('tr[data-level="0"][lay-data-index="' + item4[LAY_DATA_INDEX] + '"]').attr('data-index', i4);
|
|
|
|
// tableViewElemFIXL.find('tr[data-level="0"]').eq(i1).attr('data-index', item1[LAY_DATA_INDEX]);
|
|
|
|
})
|
|
|
|
// tableViewElemFIXR.find('tr[data-level="0"]').eq(i1).attr('data-index', item1[LAY_DATA_INDEX]);
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
that.renderTreeTable(tableViewElem.find(newNodes.map(function (value, index, array) {
|
|
|
|
that.renderTreeTable(tableViewElem.find(newNodes.map(function (value, index, array) {
|
|
|
|
return 'tr[data-index="' + value[LAY_DATA_INDEX] + '"]'
|
|
|
|
return 'tr[lay-data-index="' + value[LAY_DATA_INDEX] + '"]'
|
|
|
|
}).join(',')));
|
|
|
|
}).join(',')));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
var isParentKey = treeOptions.data.key.isParent;
|
|
|
|
var isParentKey = treeOptions.data.key.isParent;
|
|
|
@ -983,14 +1021,14 @@ layui.define(['table'], function (exports) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var childrenNodesFlat = that.treeToFlat(childrenNodes);
|
|
|
|
var childrenNodesFlat = that.treeToFlat(childrenNodes);
|
|
|
|
tableViewElem.find(childrenNodesFlat.map(function (value) {
|
|
|
|
tableViewElem.find(childrenNodesFlat.map(function (value) {
|
|
|
|
return 'tr[data-index="' + value[LAY_DATA_INDEX] + '"]'
|
|
|
|
return 'tr[lay-data-index="' + value[LAY_DATA_INDEX] + '"]'
|
|
|
|
}).join(',')).remove();
|
|
|
|
}).join(',')).remove();
|
|
|
|
|
|
|
|
|
|
|
|
tableData = that.initData();
|
|
|
|
tableData = that.initData();
|
|
|
|
// 去掉父节点的已经展开过的状态,重新执行一次展开的方法
|
|
|
|
// 去掉父节点的已经展开过的状态,重新执行一次展开的方法
|
|
|
|
parentNode['LAY_HAS_EXPANDED'] = false;
|
|
|
|
parentNode['LAY_HAS_EXPANDED'] = false;
|
|
|
|
parentNode['LAY_ASYNC_STATUS'] = 'local'; // 转为本地数据,应该规定异步加载子节点的时候addNodes的规则
|
|
|
|
parentNode['LAY_ASYNC_STATUS'] = 'local'; // 转为本地数据,应该规定异步加载子节点的时候addNodes的规则
|
|
|
|
expandNode({trElem: tableViewElem.find('tr[data-index="' + parentIndex + '"]')}, true)
|
|
|
|
expandNode({trElem: tableViewElem.find('tr[lay-data-index="' + parentIndex + '"]')}, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newNodes;
|
|
|
|
return newNodes;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1099,24 +1137,36 @@ layui.define(['table'], function (exports) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新父节点的选中状态
|
|
|
|
Class.prototype.updateParentCheckStatus = function (dataP, checked) {
|
|
|
|
Class.prototype.updateParentCheckStatus = function (dataP, checked) {
|
|
|
|
var that = this;
|
|
|
|
var that = this;
|
|
|
|
var options = that.getOptions();
|
|
|
|
var options = that.getOptions();
|
|
|
|
var treeOptions = options.tree;
|
|
|
|
var treeOptions = options.tree;
|
|
|
|
var tableId = options.id;
|
|
|
|
var tableId = options.id;
|
|
|
|
|
|
|
|
var checkName = table.config.checkName;
|
|
|
|
|
|
|
|
var childrenKey = treeOptions.data.key.children;
|
|
|
|
|
|
|
|
|
|
|
|
var dataRet = [];
|
|
|
|
var dataRet = [];
|
|
|
|
|
|
|
|
dataP[LAY_CHECKBOX_HALF] = false; // 先设置为非半选,是否为半选又下面逻辑判断
|
|
|
|
if (checked) {
|
|
|
|
if (checked) {
|
|
|
|
// 为真需要判断子节点的情况
|
|
|
|
// 为真需要判断子节点的情况
|
|
|
|
var childrenKey = treeOptions.data.key.children;
|
|
|
|
|
|
|
|
layui.each(dataP[childrenKey], function (index, item) {
|
|
|
|
layui.each(dataP[childrenKey], function (index, item) {
|
|
|
|
if (!item[table.config.checkName]) { // 只要有一个子节点为false
|
|
|
|
if (!item[checkName]) { // 只要有一个子节点为false
|
|
|
|
checked = false;
|
|
|
|
checked = false;
|
|
|
|
|
|
|
|
dataP[LAY_CHECKBOX_HALF] = true;
|
|
|
|
return true; // 跳出循环
|
|
|
|
return true; // 跳出循环
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 判断是否为半选
|
|
|
|
|
|
|
|
layui.each(dataP[childrenKey], function (index, item) {
|
|
|
|
|
|
|
|
if (item[checkName] || item[LAY_CHECKBOX_HALF]) { // 只要有一个子节点为选中或者半选状态
|
|
|
|
|
|
|
|
dataP[LAY_CHECKBOX_HALF] = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dataP[table.config.checkName] = checked;
|
|
|
|
dataP[checkName] = checked;
|
|
|
|
dataRet.push($.extend({}, dataP));
|
|
|
|
dataRet.push($.extend({}, dataP));
|
|
|
|
if (dataP[LAY_PARENT_INDEX]) {
|
|
|
|
if (dataP[LAY_PARENT_INDEX]) {
|
|
|
|
dataRet = dataRet.concat(that.updateParentCheckStatus(table.cache[tableId][dataP[LAY_PARENT_INDEX]], checked));
|
|
|
|
dataRet = dataRet.concat(that.updateParentCheckStatus(table.cache[tableId][dataP[LAY_PARENT_INDEX]], checked));
|
|
|
@ -1138,41 +1188,51 @@ layui.define(['table'], function (exports) {
|
|
|
|
var isParentKey = treeOptions.data.key.isParent;
|
|
|
|
var isParentKey = treeOptions.data.key.isParent;
|
|
|
|
var childrenKey = treeOptions.data.key.children;
|
|
|
|
var childrenKey = treeOptions.data.key.children;
|
|
|
|
var trIndex = obj.index;
|
|
|
|
var trIndex = obj.index;
|
|
|
|
|
|
|
|
var checkName = table.config.checkName;
|
|
|
|
// 修改当前节点的信息
|
|
|
|
// 修改当前节点的信息
|
|
|
|
var trData = table.cache[tableId][trIndex];
|
|
|
|
var trData = that.getNodeDataByIndex(trIndex);
|
|
|
|
// trData[table.config.checkName] = checked;
|
|
|
|
// trData[checkName] = checked;
|
|
|
|
// tableView.find('tr[data-index="' + trIndex + '"] input[name="layTableCheckbox"]').prop('checked', checked);
|
|
|
|
|
|
|
|
// 如果是一个父节点,将子节点的状态同步为当前节点的状态,并且注意更深层次的
|
|
|
|
// 如果是一个父节点,将子节点的状态同步为当前节点的状态,并且注意更深层次的
|
|
|
|
if (obj.type === 'all' || trData[isParentKey]) {
|
|
|
|
if (obj.type === 'all' || trData[isParentKey]) {
|
|
|
|
var checkedStatus = {};
|
|
|
|
var checkedStatus = {};
|
|
|
|
checkedStatus[table.config.checkName] = checked;
|
|
|
|
checkedStatus[checkName] = checked;
|
|
|
|
|
|
|
|
checkedStatus[LAY_CHECKBOX_HALF] = false;
|
|
|
|
var trs = that.updateStatus(trData ? [trData] : table.cache[tableId], checkedStatus);
|
|
|
|
var trs = that.updateStatus(trData ? [trData] : table.cache[tableId], checkedStatus);
|
|
|
|
form.render(tableView.find(trs.map(function (value) {
|
|
|
|
form.render(tableView.find(trs.map(function (value) {
|
|
|
|
return 'tr[data-index="' + value[LAY_DATA_INDEX] + '"] input[name="layTableCheckbox"]';
|
|
|
|
return 'tr[lay-data-index="' + value[LAY_DATA_INDEX] + '"] input[name="layTableCheckbox"]';
|
|
|
|
}).join(',')).prop('checked', checked));
|
|
|
|
}).join(',')).prop({checked: checked, indeterminate: false}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新父节点以及更上层节点的状态
|
|
|
|
// 更新父节点以及更上层节点的状态
|
|
|
|
if (trData && trData[LAY_PARENT_INDEX]) {
|
|
|
|
if (trData && trData[LAY_PARENT_INDEX]) {
|
|
|
|
// 找到父节点,然后判断父节点的子节点是否全部选中
|
|
|
|
// 找到父节点,然后判断父节点的子节点是否全部选中
|
|
|
|
var trDataP = table.cache[tableId][trData[LAY_PARENT_INDEX]];
|
|
|
|
var trDataP = that.getNodeDataByIndex(trData[LAY_PARENT_INDEX]);
|
|
|
|
var trsP = that.updateParentCheckStatus(trDataP, checked);
|
|
|
|
var trsP = that.updateParentCheckStatus(trDataP, checked);
|
|
|
|
layui.each(trsP, function (indexP, itemP) {
|
|
|
|
layui.each(trsP, function (indexP, itemP) {
|
|
|
|
form.render(tableView.find('tr[data-index="' + itemP[LAY_DATA_INDEX] + '"] input[name="layTableCheckbox"]').prop('checked', itemP[table.config.checkName]))
|
|
|
|
form.render(tableView.find('tr[lay-data-index="' + itemP[LAY_DATA_INDEX] + '"] input[name="layTableCheckbox"]').prop({
|
|
|
|
|
|
|
|
checked: itemP[checkName],
|
|
|
|
|
|
|
|
indeterminate: itemP[LAY_CHECKBOX_HALF]
|
|
|
|
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 半选复选框的图标处理 todo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 全选图标的状态更新
|
|
|
|
// 全选图标的状态更新
|
|
|
|
obj.isAll = true;
|
|
|
|
obj.isAll = true;
|
|
|
|
|
|
|
|
var isIndeterminate = false;
|
|
|
|
layui.each(table.cache[tableId], function (i1, item1) {
|
|
|
|
layui.each(table.cache[tableId], function (i1, item1) {
|
|
|
|
if (!item1[table.config.checkName]) {
|
|
|
|
if (item1[checkName] || item1[LAY_CHECKBOX_HALF]) {
|
|
|
|
|
|
|
|
isIndeterminate = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!item1[checkName]) {
|
|
|
|
obj.isAll = false;
|
|
|
|
obj.isAll = false;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
form.render(tableView.find('input[name="layTableCheckbox"][lay-filter="layTableAllChoose"]').prop('checked', obj.isAll));
|
|
|
|
isIndeterminate = isIndeterminate && !obj.isAll;
|
|
|
|
|
|
|
|
form.render(tableView.find('input[name="layTableCheckbox"][lay-filter="layTableAllChoose"]').prop({
|
|
|
|
|
|
|
|
'checked': obj.isAll,
|
|
|
|
|
|
|
|
indeterminate: isIndeterminate
|
|
|
|
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|