Commit 4b45e918 authored by 覃振观's avatar 覃振观 👶

Grid 下拉框

parent 996b5748
...@@ -178,7 +178,10 @@ function checkArrayMapper(str) { ...@@ -178,7 +178,10 @@ function checkArrayMapper(str) {
} }
/** /**
* Grid 编辑前触发。 这里记录当前编辑框 对应的 Grid 行 rowIndex 和列 property *     
* Grid 编辑前触发。 这里记录当前编辑框 对应的 Grid 行 rowIndex 和列 property <br> &nbsp;&nbsp;&nbsp;&nbsp;
* 这里根据 UI ID生成规则封装。 需要根据此规则维护。 <br> &nbsp;&nbsp;&nbsp;&nbsp;
* 编辑前,根据 UI 生成的编辑框命名规则,定位到当前编辑栏目。修改数据时以此栏目位置为定位标准修改对应数据集。只记录当前栏目,使用完后需要清除。
* @param options * @param options
* @private * @private
*/ */
...@@ -187,64 +190,90 @@ function onBeforeEdit_(options) { ...@@ -187,64 +190,90 @@ function onBeforeEdit_(options) {
options.onBeforeEdit = function(editParm, gg){ options.onBeforeEdit = function(editParm, gg){
let domIds = editParm.column.__domid.split('|'), recordId = editParm.record.__id, colName = editParm.column.name; let domIds = editParm.column.__domid.split('|'), recordId = editParm.record.__id, colName = editParm.column.name;
let parentDomId = domIds[0]+'|'+2+'|'+recordId; // +'|'+domIds[2]; let parentDomId = domIds[0]+'|'+2+'|'+recordId; // +'|'+domIds[2];
let domId = domIds[0]+'|'+2+'|'+recordId +'|'+domIds[2];
let rowDOM; let rowDOM;
if(!(rowDOM = document.getElementById(parentDomId))) { if(!(rowDOM = document.getElementById(parentDomId))) {
parentDomId = domIds[0]+'|'+1+'|'+recordId; parentDomId = domIds[0]+'|'+1+'|'+recordId;
rowDOM = document.getElementById(parentDomId) rowDOM = document.getElementById(parentDomId)
} }
let mapper = window.dataMapping.mapper; let mapper = window.dataMapping.mapper;
let rowId = rowDOM.childNodes[0].childNodes[0].innerText; let rowIndex = rowDOM.childNodes[0].childNodes[0].innerText;
let mapperEntry = mapper[colName]; let mapperEntry = mapper[colName];
let currentMapper = checkArrayMapper(domIds[0]); let currentMapper = checkArrayMapper(domIds[0]);
if(currentMapper.hasOwnProperty("beanName")) { if(currentMapper.hasOwnProperty("beanName")) {
if(!mapperEntry[currentMapper.beanName]) { if(mapperEntry[currentMapper.beanName]) {
console.error("dataMapping 中,无法找到该 DOMId 的映射。请检查!"); mapperEntry[currentMapper.beanName]['rowIndex'] = rowIndex;
mapperEntry[currentMapper.beanName]['colName'] = colName;
mapperEntry[currentMapper.beanName]['domId'] = domId;
mapperEntry[currentMapper.beanName][rowIndex] = editParm.rowindex;
} else { } else {
//mapperEntry[currentMapper.beanName]['rowId'] = parentDomId; // mapperEntry[currentMapper.beanName][rowIndex] = colName;
mapperEntry[currentMapper.beanName][rowId] = colName; // console.error("dataMapping 中,无法找到该 DOMId 的映射。请检查!");
} }
} }
originalOnBeforeEdit.call(this, editParm, '11'); originalOnBeforeEdit.call(this, editParm, '11');
} }
} }
function listeningSearchbox(elId, options) { /**
* 监听 下拉框初始化 ,使选中值时维护 dataSet。显示值需要自己处理。
* @param elId 需要渲染的下拉框的 DOMId
* @param options
*/
function listeningSearchbox(elId, options, gridId) {
const originalOnChange = options.onChange; const originalOnChange = options.onChange;
options.onChange = function(value, data) { options.onChange = function(value, data, fillInValue) {
let eleName = this.element[0].name; let eleName = this.element[0].name, beanName = '';
let currentMapper = window.dataMapping.mapper[eleName]; let currentMapper = window.dataMapping.mapper[eleName];
if(!currentMapper) { if(!currentMapper) {
console.error("找不到该映射,请检查映射配置是否存在该配置: "+ eleName); console.error("找不到该映射,请检查映射配置是否存在该配置: "+ eleName);
} }
let fillInValue;
Object.entries(currentMapper).forEach(mapper => { Object.entries(currentMapper).forEach(mapper => {
let property = ""; let property = "";
if(eleName.split('_').length > 1) { if(eleName.split('_').length > 1) {
property = eleName.split('_')[1]; property = eleName.split('_')[1];
} else { } else {
let beanName = mapper[0]; beanName = mapper[0];
property = mapper[1]; property = mapper[1];
if(typeof property== 'string') { if(typeof property== 'string') {
// ------------------ Form 下拉框执行此逻辑 ------------------
window.dataSet.newData[beanName][property] = data[property]; window.dataSet.newData[beanName][property] = data[property];
fillInValue = data[property]; fillInValue = data[property];
} else if(property instanceof Object) { } else if(property instanceof Object) {
let entry = Object.entries(property); // ------------------ Grid 下拉框执行此逻辑 ------------------
let rowIndex = entry[0]; if(property.rowIndex) {
let propertyName = entry[1]; let rowIndex = property.rowIndex;
window.dataSet.newData[beanName].compares[rowIndex] let propertyName = property.colName;
let domId = property.domId;
window.dataSet.newData[beanName].compares[rowIndex][propertyName] = data[propertyName];
fillInValue = domId;
let gridEdit = window.dataGrid['fronColorsGrid'].editor;
if(gridEdit.editParm.column.editor.type === 'select') {
let showProperty = gridEdit.editParm.column.editor.showProperty
window.dataGrid[gridId].editor.editParm.record[propertyName] = data[showProperty];
}
property.rowIndex = null;
property.colName = null;
property.domId = null;
} }
} }
}
}) })
if(fillInValue) {
originalOnChange.call(this, value, data, fillInValue); originalOnChange.call(this, value, data, fillInValue);
} }
}
$(elId).searchbox(options); $(elId).searchbox(options);
} }
/**
* &nbsp;&nbsp;&nbsp;&nbsp;
* Gria 中的下拉框 用此方式初始化。此下拉框维护 dataSet, 显示值需要自己处理。
* @param propertyName GridId_propertyName,需要以此定位到需要展开下拉框的栏目(临时)
* @param options
*/
function listeningGridSearchbox(propertyName, options) { function listeningGridSearchbox(propertyName, options) {
if(!window.gridSearchboxOptions) { if(!window.gridSearchboxOptions) {
window.gridSearchboxOptions = {}; window.gridSearchboxOptions = {};
...@@ -255,7 +284,9 @@ function listeningGridSearchbox(propertyName, options) { ...@@ -255,7 +284,9 @@ function listeningGridSearchbox(propertyName, options) {
function DropdownTrigger(node) { function DropdownTrigger(node) {
let nodeId = node.id; let nodeId = node.id;
let tempId = nodeId.slice(0, nodeId.lastIndexOf('_')); let tempId = nodeId.slice(0, nodeId.lastIndexOf('_'));
listeningSearchbox('#'+nodeId, window.gridSearchboxOptions[tempId]); if(node.getAttribute('select')) {
listeningSearchbox('#'+nodeId, window.gridSearchboxOptions[tempId], nodeId.split('_')[0]);
}
} }
/** /**
...@@ -348,6 +379,10 @@ function listeningGrid(elId, options) { ...@@ -348,6 +379,10 @@ function listeningGrid(elId, options) {
} }
addObserver(elId); addObserver(elId);
var gridManager = UICtrl.grid(elId, options); var gridManager = UICtrl.grid(elId, options);
if(!window.dataGrid){
window.dataGrid = {};
}
window.dataGrid[elId.slice(1)] = gridManager;
return gridManager; return gridManager;
} }
...@@ -384,12 +419,12 @@ function listenerContent(event) { ...@@ -384,12 +419,12 @@ function listenerContent(event) {
// Grid 时执行此逻辑 // Grid 时执行此逻辑
if(control === 'grid') { if(control === 'grid') {
debugger; debugger;
tryForEach(Object.entries(beanMapping), mapperEntry => { Object.entries(beanMapping).forEach(mapperEntry => {
let mapperKey = mapperEntry[0], mapperVal = mapperEntry[1]; let mapperKey = mapperEntry[0], mapperVal = mapperEntry[1];
Object.entries(mapperEntry[1]).forEach(rowEntry => { Object.entries(mapperEntry[1]).forEach(rowEntry => {
let rowId = rowEntry[0]; let rowId = rowEntry[0];
if(rowEntry[1].rowIndex != undefined) { if(rowEntry[1] !== undefined) {
if(rowEntry[1].rowIndex === inputIds[2] * 1) { if(rowEntry[1] === inputIds[2] * 1) {
window.dataSet.newData[mapperKey].compares[rowId][inputIds[1]] = event.target.value; window.dataSet.newData[mapperKey].compares[rowId][inputIds[1]] = event.target.value;
console.log('Input value changed:', event.target.value); console.log('Input value changed:', event.target.value);
} }
......
...@@ -57,18 +57,18 @@ function initializateSelectC() { ...@@ -57,18 +57,18 @@ function initializateSelectC() {
}); });
} }
function initGridSearchbox() { function initGridSearchbox() {
listeningGridSearchbox('fronColorsGrid_colorId', { listeningGridSearchbox('fronColorsGrid_colorId', {
type: "product", type: "product",
name: "color", name: "color",
onChange: function (value, data, fillInValue) { onChange: function (value, data, fillInValue) {
console.log('fillInValue : '+ fillInValue); console.log('fillInValue : '+ fillInValue);
debugger;
// $('#selectedTechnology').val(data.productTechnologyName)
} }
}) })
} }
function initializeUI() { function initializeUI() {
UICtrl.layout("#layout",{ UICtrl.layout("#layout",{
heigth:'280px', heigth:'280px',
...@@ -217,9 +217,9 @@ function faceGrid(elId, data) { ...@@ -217,9 +217,9 @@ function faceGrid(elId, data) {
var gridManager = listeningGrid(elId, { var gridManager = listeningGrid(elId, {
columns: [ columns: [
{ display: "颜色名称", name: "colorId", width: 140, minWidth: 60, type: "string", align: "left", editor: { { display: "颜色名称", name: "colorId", width: 140, minWidth: 60, type: "string", align: "left", editor: {
type: 'select' type: 'select', showProperty: 'colorName'
}}, }},
{ display: "油墨覆盖率(%)", name: "coverageRate", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: true } } { display: "油墨覆盖率(%)", name: "coverageRate", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text'} }
], ],
toolbar: toolbarOptions, toolbar: toolbarOptions,
dataType: "local", dataType: "local",
...@@ -232,8 +232,9 @@ function faceGrid(elId, data) { ...@@ -232,8 +232,9 @@ function faceGrid(elId, data) {
onBeforeEdit : function(editParm, gg) { onBeforeEdit : function(editParm, gg) {
console.log('original run onBeforeEdit()'); console.log('original run onBeforeEdit()');
}, },
onDblClickRow : function(data, rowindex, rowobj) { onAfterEdit: function() {
} debugger;
},
}); });
} }
......
...@@ -254,10 +254,10 @@ public class ProductApplicationImpl extends BaseApplication implements ProductAp ...@@ -254,10 +254,10 @@ public class ProductApplicationImpl extends BaseApplication implements ProductAp
} }
/** /**
* description 持久化数据. * description 持久化数据. <br>&nbsp;&nbsp;&nbsp;&nbsp;
* <br>&nbsp;&nbsp;Entity 时,如果 ID 为空执行 Persist,否则执行 Merge * Entity 时,如果 ID 为空执行 Persist,否则执行 Merge <br>&nbsp;&nbsp;&nbsp;&nbsp;
* <br>&nbsp;&nbsp;List 时,要求数据集格式 : * List 时,要求数据集格式 : <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* <br>&nbsp;&nbsp;&nbsp;&nbsp;HashMap { ”add“: List< Entity >, ”up“: List< Entity >, ”del“: List< Entity > } * HashMap {”add“: List< Entity >,”up“: List< Entity >,”del“: List< Entity >}
* @param entitys 持久化数据集合 Set { Entity, HashMap } * @param entitys 持久化数据集合 Set { Entity, HashMap }
* @author qinzhenguan * @author qinzhenguan
* @createDate 2023/12/26 16:44 * @createDate 2023/12/26 16:44
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment