gpt4 book ai didi

select - 无法在 slickgrid 中使用选择下拉插件

转载 作者:行者123 更新时间:2023-12-02 06:44:32 25 4
gpt4 key购买 nike

我需要在 slickgrid 的标题中添加一个下拉列表。正常的选择下拉菜单工作正常。我需要使用下拉插件来赋予其正确的外观和感觉。每当我这样做时,下拉部分就会隐藏在标题中。

感谢任何帮助。

jsfiddle 的链接在这里:

https://jsfiddle.net/yudhir/31bozsge/2/

<div id="myGrid" style="width: 600px; height: 500px;"></div>


var grid;
var dataView;

var buttonFormat = function (row, cell, value, columnDef, dataContext) {
return "";
}

var columns = [
{id: "title", name: "Title", field: "title"},
{id: "term", name: "Term", field: "term"},
{id: "%", name: "% Complete", field: "percentComplete"},
{id: "detail", name: "Detail", field: "detail",formatter: buttonFormat}
];

var options = {
rowHeight: 25,
editable: false,
enableAddRow: false,
enableCellNavigation: true,
forceFitColumns: false,
headerrowheight:100,
multiColumnSort: true,
showHeaderRow: true,
explicitInitialization: true
};

$(function () {
var data = [];
for (var i = 0; i < 30; i++) {
var days = Math.round(Math.random() * 10);
data[i] = {
id: i ,
title: "Task " + i,
term: days + " days",
percentComplete: Math.round(Math.random() * 100),
description: "We are working hard " + days + " days!",
detail: null,
toString:function(){
var str = "";
str += "Title:" + this.title + "<br/>";
str += "Term:" + this.term + "<br/>";
str += "Comp:" + this.percentComplete + "<br/>";
str += "<b>" + this.description + "</b>";
return str;
}
};
}

dataView = new Slick.Data.DataView();
dataView.beginUpdate();
dataView.setItems(data);
dataView.endUpdate();

grid = new Slick.Grid("#myGrid", dataView, columns, options);

grid.onClick.subscribe(function (e, args) {
if ($(e.target).hasClass("btn")) {
var item = dataView.getItem(args.row);
openDialog(item);
}
e.stopImmediatePropagation();
});

grid.onHeaderRowCellRendered.subscribe(function(e, args) {
$(args.node).empty();
if(args.column.id=="detail"){

$("<select style='width: 70px;'><option value=''>All</option><option value='Activation'>Activation</option><option value='Deactivation'>Deactivation</option><option value='Upload'>Upload</option></select>")
.data("columnId", args.column.id)
.val("")
.appendTo(args.node);
}


});
grid.init();

});

var openDialog = function(row){
var dom = "<div>" + row.toString() + "</div>";
$(dom).dialog();
};
$('select').each(function () {

// Cache the number of options
var $this = $(this),
numberOfOptions = $(this).children('option').length;

// Hides the select element
$this.addClass('s-hidden');

// Wrap the select element in a div
$this.wrap('<div class="select"></div>');

// Insert a styled div to sit over the top of the hidden select element
$this.after('<div class="styledSelect"></div>');

// Cache the styled div
var $styledSelect = $this.next('div.styledSelect');

// Show the first select option in the styled div
$styledSelect.text($this.children('option').eq(0).text());

// Insert an unordered list after the styled div and also cache the list
var $list = $('<ul />', {
'class': 'options'
}).insertAfter($styledSelect);

// Insert a list item into the unordered list for each select option
for (var i = 0; i < numberOfOptions; i++) {
$('<li />', {
text: $this.children('option').eq(i).text(),
rel: $this.children('option').eq(i).val()
}).appendTo($list);
}

// Cache the list items
var $listItems = $list.children('li');

// Show the unordered list when the styled div is clicked (also hides it if the div is clicked again)
$styledSelect.click(function (e) {
e.stopPropagation();
$('div.styledSelect.active').each(function () {
$(this).removeClass('active').next('ul.options').hide();
});
$(this).toggleClass('active').next('ul.options').toggle();
});

// Hides the unordered list when a list item is clicked and updates the styled div to show the selected list item
// Updates the select element to have the value of the equivalent option
$listItems.click(function (e) {
e.stopPropagation();
$styledSelect.text($(this).text()).removeClass('active');
$this.val($(this).attr('rel'));
$list.hide();
/* alert($this.val()); Uncomment this for demonstration! */
});

// Hides the unordered list when clicking outside of it
$(document).click(function () {
$styledSelect.removeClass('active');
$list.hide();
});

});


body{
font-size:10px;
}
.s-hidden {
visibility:hidden;
padding-right:10px;
}
.select {
cursor:pointer;
display:inline-block;
position:relative;
font:normal 11px/22px Arial, Sans-Serif;
color:black;
border:1px solid #ccc;
}
.styledSelect {
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
background-color:white;
padding:0 10px;
font-weight:bold;
}
.styledSelect:after {
content:"";
width:0;
height:0;
border:5px solid transparent;
border-color:black transparent transparent transparent;
position:absolute;
top:9px;
right:6px;
}
.styledSelect:active, .styledSelect.active {
background-color:#eee;
}
.options {
display:none;
position:absolute;
top:100%;
right:0;
left:0;
z-index:999;
margin:0 0;
padding:0 0;
list-style:none;
border:1px solid #ccc;
background-color:white;
-webkit-box-shadow:0 1px 2px rgba(0, 0, 0, 0.2);
-moz-box-shadow:0 1px 2px rgba(0, 0, 0, 0.2);
box-shadow:0 1px 2px rgba(0, 0, 0, 0.2);
}
.options li {
padding:0 6px;
margin:0 0;
padding:0 10px;
}
.options li:hover {
background-color:#39f;
color:white;
}
.slick-headerrow-columns {
height: 100px !important;
}

最佳答案

导致您的问题的故障是为标题行及其列定义设置的 SlickGrids 默认样式,即:

overflow: hidden;

将标题行和列的 CSS 样式更改为:

.slick-headerrow  {
overflow: unset !important;
}

.slick-headerrow-column, .slick-headerrow-columns {
overflow: unset;
}

并将网格视口(viewport) z-index 设置为 -1 会使下拉列表按预期显示。

我已经更新了您最新的JSFiddle有了它,您现在只需处理选择元素的行高和宽度。

关于select - 无法在 slickgrid 中使用选择下拉插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34431312/

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