Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery数据表上下文菜单未出现_Jquery_Jquery Ui_Contextmenu_Jquery Datatables_Jquery Callback - Fatal编程技术网

jquery数据表上下文菜单未出现

jquery数据表上下文菜单未出现,jquery,jquery-ui,contextmenu,jquery-datatables,jquery-callback,Jquery,Jquery Ui,Contextmenu,Jquery Datatables,Jquery Callback,我使用以下from在表行的右键单击上显示上下文菜单。添加此代码后,网页的默认功能已被禁用,但上下文菜单未显示。怎么了 "fnDrawCallback": function () { $('#example tr').on('mouseenter', function () { $(this).contextMenu({ menu: 'productionRightClickMenu'

我使用以下from在表行的右键单击上显示上下文菜单。添加此代码后,网页的默认功能已被禁用,但上下文菜单未显示。怎么了

"fnDrawCallback": function () {
            $('#example tr').on('mouseenter', function () {       
                $(this).contextMenu({
                    menu: 'productionRightClickMenu'
                },
            function (action, el, pos) {
                alert("hi");         
            });
            });
        }
在我对datatable使用服务器端处理后,我在网格上使用的常用上下文菜单不起作用

    //Function for context menu
(function ($, window) {

    $.fn.contextMenu = function (settings) {

        return this.each(function () {

            // Open context menu
            $(this).on("contextmenu", function (e) {
                //open menu
                $(settings.menuSelector)
                    .data("invokedOn", $(e.target))
                    .show()
                    .css({
                        position: "absolute",
                        left: getLeftLocation(e),
                        top: getTopLocation(e)
                    })
                    .off('click')
                    .on('click', function (e) {
                        $(this).hide();

                        var $invokedOn = $(this).data("invokedOn");
                        var $selectedMenu = $(e.target);

                        settings.menuSelected.call(this, $invokedOn, $selectedMenu);
                    });

                return false;
            });

            //make sure menu closes on any click
            $(document).click(function () {
                $(settings.menuSelector).hide();
            });
        });

        function getLeftLocation(e) {
            var mouseWidth = e.pageX;
            var pageWidth = $(window).width();
            var menuWidth = $(settings.menuSelector).width();

            // opening menu would pass the side of the page
            if (mouseWidth + menuWidth > pageWidth &&
                menuWidth < mouseWidth) {
                return mouseWidth - menuWidth;
            }
            return mouseWidth;
        }

        function getTopLocation(e) {
            var mouseHeight = e.pageY;
            var pageHeight = $(window).height();
            var menuHeight = $(settings.menuSelector).height();

            // opening menu would pass the bottom of the page
            if (mouseHeight + menuHeight > pageHeight &&
                menuHeight < mouseHeight) {
                return mouseHeight - menuHeight;
            }
            return mouseHeight;
        }

    };
})(jQuery, window);
    //for context menu

//$(document).on('keydown', '.inputs', function (e) {

$("#example td").contextMenu({
    menuSelector: "#contextMenu",
    menuSelected: function (invokedOn, selectedMenu) {
        var value = invokedOn.parent().children(':first').text();

        $.ajax({
            url: "../xyz/GetItemInfoDetails",
            type: 'POST',
            dataType: 'json',
            data: { "item_id": value },
            success: function (data) {
                if (data.ItemID != null) {

                    $("#value_itemId").html(data.ItemID);
                    $("#value_ItemDescription").html(data.ItemDescription);
                    $("#value_ItemGroup").html(data.ItemGroup);
                    $("#value_ItemCategory").html(data.ItemCategory);
                    $("#value_ItemUnitOfMesure").html(data.ItemUnitOfMesure);
                }
            }
        });
        $("#itemdetailsmodal").modal('show');

    }
});

在实例化datatable时使用fnRowCallback选项。然后在它的函数中创建上下文菜单

"fnRowCallback": function (nRow){
     $(nRow).on('mousenter', function () {       
            $(this).contextMenu({
                menu: 'productionRightClickMenu'
            },
        function (action, el, pos) {
            alert("hi");         
        });
     });
 } 

类似的方法可能适用于nRow是对表中选定行的回调

只有一个jQuery dataTables,但有多个jQuery ContextMenu-您使用的是什么ContextMenu?在这里实例化是什么意思。。。。我试了试鼠标进入;在上下文菜单上,加载时未按预期工作。。我尝试了你的建议..将输入错误的mousenter改为mouseenter。。。它会起作用的