gpt4 book ai didi

AG-Grid 将 Bootstrap-Select 渲染为下拉列表

转载 作者:行者123 更新时间:2023-12-01 04:43:50 41 4
gpt4 key购买 nike

我已经实现了可编辑的 AG-Grid。在网格中,一列显示玩家所在的国家,如下图:

enter image description here

现在在最后一列中,当用户单击单元格时,我想将可用国家/地区列表显示为下拉列表。

默认情况下,AG-Grid 显示正常下拉列表。我想用 Bootstrap-select 替换它。

为了实现这一点,我实现了自定义选择器并使用 Bootstrap-select图书馆。

但是当单击单元格时,不会呈现下拉列表。虽然在控制台中我没有收到任何错误。

这是我的自定义单元格编辑器的代码:

var selectCellEdior = function () { };
selectCellEdior.prototype = {
init: function (params) {

selector = document.createElement('select');

for(var i = 0; i < params.values.length; i++) {
var option = params.values[i];
$('<option />', { value: option, text: option }).appendTo(selector);
}

this.cellSelector = selector;

$(this.cellSelector).selectpicker({ size: 'auto' });


},
getValue: function () {
return $(this.cellSelector).find('.btn-text').text();
},
getGui: function () {
return this.cellSelector;
},
destroy: function () {
$(this.cellSelector).remove();
}
};

这是 Sample Code

我不明白这是什么问题。

最佳答案

问题是 selectpicker jQuery 方法似乎添加了 display: none到选择元素。 Ag-Grid 正在将它添加到您看不到的 DOM 中。另外 getValue函数不返回所选选项的文本。

以下更改为 getValuegetGui将使网格工作:

  ...
getValue: function () {
return $(this.cellSelector).val();
},
getGui: function () {
this.cellSelector.style.display = 'block';
return this.cellSelector;
},
...

Here is the modified Plunker

关于AG-Grid 将 Bootstrap-Select 渲染为下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48620228/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com