简体   繁体   English

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

[英]Not able to use select dropdown plugin in slickgrid

I have a requirement to add a dropdown in header in slickgrid. 我需要在slickgrid中添加标题的下拉列表。 Normal select dropdown works fine. 正常选择下拉列表工作正常。 I need to use a dropdown plugin to give it proper look and feel. 我需要使用下拉插件来提供正确的外观和感觉。 Whenever i do that, the dropdown part gets hidden within the header. 每当我这样做时,下拉部分就会隐藏在标题中。

Any help is appreciated. 任何帮助表示赞赏。

The link to jsfiddle is here: jsfiddle的链接在这里:

https://jsfiddle.net/yudhir/31bozsge/2/ 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;
}

The glitch causing your problem was the SlickGrids default style set for the header row and it's column definition, which is: 导致问题的故障是为标题行设置的SlickGrids默认样式及其列定义,即:

overflow: hidden ; 溢出: 隐藏 ;

Changing the header rows and columns CSS style to: 将标题行和列CSS样式更改为:

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

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

and setting the grids viewport z-index to -1 causes your dropdown to display as intended. 并将网格视口z-index为-1会使您的下拉列表按预期显示。

I have updated your latest JSFiddle with it, you now just need to take care of the row height and the width of your select element. 我用它更新了你最新的JSFiddle ,你现在只需要处理你选择元素的行高和宽度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 下拉菜单无法选择-角度4 - dropdown menu not able to select - angular 4 在SlickGrid中选中带复选框的行 - Select rows with checkbox in SlickGrid 如何在WordPress插件中保存选择选项下拉菜单 - how to save a select option dropdown in a wordpress plugin jQuery-使用输入字段或选择下拉列表 - Jquery - Use Input Field or Select DropDown 如何在Angular Directive中使用选择选项下拉菜单? - How to use a select option dropdown in an Angular Directive? 如何使用selenium webdriver选择Bootstrap选择下拉菜单选项? - How to use selenium webdriver to select an option of Bootstrap select dropdown menu? 使用从条件创建的选择下拉列表中使用不同的值 - Use different value from a select dropdown that is created from a condition coldfusion-如何使用cfloop文件为选择下拉列表创建数组 - coldfusion - how to use cfloop file to create an array for a select dropdown 是否有任何插件可以将文本框列表链接到选择下拉列表并使它们保持同步 - is there any plugin that can link a list of textboxes to a select dropdown and keep them in sync 元框插件使用php数组作为选择选项? - meta box plugin use php array as select options?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM