0

我有一个非常奇怪的问题......我有这个功能可以在剑道 ui 网格上显示上下文菜单

var my = {};

my.contextMenu = function (options) {
    if (!options) { alert('You have not specified any options!'); return; }
    if (!options.trigger) { alert('You must supply a trigger element selector!'); return; }
    if (!options.menu) { alert('You must specify a menu element selector!'); return; }
    if (!options.callback) { alert('You must specify a callback function!'); return; }
    options.rightButton = options.rightButton || true;
    options.zindex = options.zindex || 999000;

    var menu = $(options.menu);
    if (!menu.parent().hasClass('k-context-menu')) menu.wrap(document.createElement('div'));
    menu = menu.parent().addClass('k-context-menu').hide();

    var panel = $('#ctxMenuPanel');
    if (!panel[0]) panel = $(document.createElement('div')).attr('id', 'ctxMenuPanel');

    menu.visible = false;
    menu.addClass('k-calendar-container k-popup k-group k-reset');
    menu.css({ position: 'absolute', 'background-color': 'white', display: 'none', 'z-index': options.zindex + 1, padding: 0 });

    menu.close = function () { menu.fadeOut('fast'); panel.hide(); menu.visible = false; };
    menu.show = function () {
        if (menu.visible) {
            menu.close();
        } else {
            var pos = $(this).offset(); pos.top += 10; pos.left += 15;
            panel.css({ top: 0, left: 0, width: '100%', height: $(document).height(), 'background-color': 'transparent' }).show();
            menu.data('trigger', $(this));
            menu.css(pos).fadeIn('fast');
            menu.visible = true;
        }
        return false;
    };

    panel.css({ position: 'absolute', display: 'none', 'z-index': options.zindex });
    panel.appendTo('html').click(menu.close);

    var list = menu.find('ul').css({ 'list-style-type': 'none', padding: 0, margin: 0 });
    list.find('li').click(function () {
        menu.close();
        options.callback($(this), menu.data('trigger'));
    }).mouseenter(function () {
        $(this).addClass('k-state-hover');
    }).mouseleave(function () {
        $(this).removeClass('k-state-hover');
    }).mousedown(function () {
        $(this).addClass('k-state-selected');
    }).mouseup(function () {
        $(this).removeClass('k-state-selected');
    }).css({ margin: 0, cursor: 'pointer', padding: '3px 7px 3px 7px' });

    // bind the triggers
    $(options.trigger).each(function (index) {
        if (options.leftButton) $(this).click(menu.show);
        if (options.rightButton) $(this).bind("contextmenu", menu.show);
    });
};

function ctxCallback(item, trigger) {
    var trigVal = trigger.attr('id');
    var rowId = trigger.parent().attr('id'); // get the row of the parent since I used the TD as my trigger.

    if (typeof trigVal == 'undefined') trigVal = trigger.html();

    if (typeof rowId == 'undefined') rowId = '';
    else rowId = ' on row ' + rowId;

    alert('Trigger ' + trigVal + rowId + ' clicked: ' + item.text().trim());
}

$(document).ready(function () {

//    alert('ok');
    $('#grid td').click(function (e) {
        $('#testMenu li').eq(0).text('detail of cell ' + $(e.target).text());
    });

    my.contextMenu({
        trigger: '.menu, #grid td',
        leftButton: true,
        rightButton: true,
        menu: '#testMenu',
        callback: ctxCallback
    });

    // add a row id to each row so that we can illustrate how to read them in the callback
    $('#myGrid tr').each(function() {
        $(this).attr('id', 'Row' +  $(this).index('tr'));
    });

如果我评论警报,网格将不会显示上下文菜单...同时,如果我使用警报,它会起作用...到底发生了什么?

我的网格使用 MVC Kendo 包装器定义为

@(Html.Kendo()
.Grid<IDEA20.DO.Admin.Utente>()
.Name("grid")
.Columns(columns =>
    {
        columns.Bound(x => x.IDDipendente).Visible(false);
        columns.Bound(x => x.IDUtente);
        columns.Bound(x => x.Nominativo);
        columns.Bound(x => x.Societa);
        columns.Bound(x => x.Filiale);
        columns.Bound(x => x.Ruolo);
        columns.Bound(x => x.Profilo);
        columns.Bound(x => x.Funzioni);
        columns.Bound(x => x.Stato);
        columns.Bound(x => x.AccessoEureka);

    })
.DataSource(dataSource => dataSource
    .Ajax()
    .Read(read => read.Action("GetListaUtenti", "GestioneUtenti"))
)
    //.HtmlAttributes(new { style = "height:430px;" })
    //.Sortable()
    .Pageable()
    //.Groupable()
    .Scrollable()

) 在 Index.cshtml 的顶部

谢谢

4

0 回答 0