我会让它变得简单。我花了 2 天时间用纯 JavaScript 制作一个。您可以根据自己的 Angular 需求对其进行调整。
包括
<script type="text/javascript" src="/assets/themes/frt/vendors/custom/bootstrap-multiselect/js/bootstrap-multiselect.js"></script>
<script type="text/javascript" src="/assets/themes/frt/vendors/custom/bootstrap-multiselect/js/bootstrap-multiselect.js"></script>
风格
<style> #commentSelection { width: 100%; } .input-widget-popup { width: 250px; height: 100px; } table { width: 100%; height: 100%; } td, th { text-align: center; padding: 8px; } </style>
自定义
var selectedComments = [];
class CommentCellRenderer {
init(params) {
this.eGui = document.createElement('span');
if (params.value !== "" && params.value !== undefined && params.value !== null) {
this.eGui.innerHTML = params.value;
}
}
getGui() {
return this.eGui;
}
}
class CommentPopupCellEditor {
init(params) {
this.container = document.createElement('div');
this.container.setAttribute('class', 'input-widget-popup');
this._createTable(params);
this.params = params;
var commentUids = '';
var commentNames = '';
var rowSelectedComments = selectedComments.filter(comment => comment.rowId === params.node.id);
for (var i = 0; i < rowSelectedComments.length; i++) {
if (i > 0) {
commentUids += ',';
commentNames += ',';
}
commentUids += rowSelectedComments[i].uid;
commentNames += rowSelectedComments[i].name;
}
this.selectComment(commentUids, commentNames);
}
selectComment(commentUids, commentNames) {
this.commentList = commentNames;
var rowNode = gridOptions.api.getRowNode(this.params.node.id);
rowNode.setDataValue('comment_uid', commentUids);
rowNode.setDataValue('comment_name', commentNames);
setTimeout(() => {
App.autoSizeAll(gridOptions);
}, 1000);
}
getGui() {
return this.container;
}
afterGuiAttached() {
var that = this;
$('#commentSelection').multiselect({
buttonWidth: '100%',
onChange: function(element, checked) {
var x = element[0];
var commentUid = $(x).val().toString();
var commentName = $(x).text().toString();
if (checked) {
var index = selectedComments.filter(comment => comment.rowId === that.params.node.id).map(function(e) { return e.uid; }).indexOf(commentUid);
if (index === -1) {
selectedComments.push({
rowId: that.params.node.id,
uid: commentUid,
name: commentName
});
}
}
else {
selectedComments = selectedComments.filter(comment => comment.rowId !== that.params.node.id || comment.uid !== commentUid);
}
var commentUids = '';
var commentNames = '';
var rowSelectedComments = selectedComments.filter(comment => comment.rowId === that.params.node.id);
for (var i = 0; i < rowSelectedComments.length; i++) {
if (i > 0) {
commentUids += ',';
commentNames += ',';
}
commentUids += rowSelectedComments[i].uid;
commentNames += rowSelectedComments[i].name;
}
that.selectComment(commentUids, commentNames);
}
});
this.container.focus();
}
getValue() {
return this.commentList;
}
isPopup() {
return true;
}
_createTable(params) {
this.container.innerHTML = `
<table>
<tr>
<th><?php echo COMMENTS; ?></th>
</tr>
<tr>
<td>
<select id="commentSelection" multiple="multiple">
</select>
</td>
</tr>
</table>
`;
this.commentDropdown = this.container.querySelector('#commentSelection');
for (let i = 0; i < comments.length; i++) {
const option = document.createElement('option');
option.setAttribute('value', comments[i].uid.toString());
var index = selectedComments.filter(comment => comment.rowId === params.node.id).map(function(e) { return e.uid; }).indexOf(comments[i].uid);
if (index !== -1) {
option.selected = true;
}
option.innerText = comments[i].name;
this.commentDropdown.appendChild(option);
}
}
}
参考
{headerName: '', field: 'comment_name', editable: true, cellEditor: 'commentPopupCellEditor', cellRenderer: 'commentCellRenderer'},
选项
components: {
commentCellRenderer: CommentCellRenderer,
commentPopupCellEditor: CommentPopupCellEditor,
},
How it looks like