【问题标题】:How to custom tooltip such as contains some button in grid's cell tooltip in Kendo UI MVC?如何自定义工具提示,例如在 Kendo UI MVC 的网格单元工具提示中包含一些按钮?
【发布时间】:2014-04-12 16:48:02
【问题描述】:

在单元格的工具提示中,我想添加一些按钮或菜单,例如打开按钮。当我将鼠标悬停在单元格上方时,工具提示显示按钮。当我单击按钮时,它将打开一个窗口。剑道网格能做到吗?

【问题讨论】:

    标签: jquery kendo-ui kendo-grid kendo-asp.net-mvc kendo-tooltip


    【解决方案1】:

    以下是您将如何使用 JS 进行操作;您需要做的就是使用适当的 MVC 包装器(Html.Kendo().Grid()@(Html.Kendo().Tooltip()Html.Kendo().Window()(尽管如果您想使用 jQuery click 事件,您可能需要对窗口使用纯 JS)):

    网格:

    var grid = $("#grid").kendoGrid({
        dataSource: dataSource,
        columns: [{
            field: "Id",
            title: "Id",
            filterable: false
        }, {
            field: "StatusText",
            title: "String value"
        }, {
            field: "ToolTip",
            title: "Tool tip column",
            template: "<span class='tooltip'>#= data.ToolTip #</span>"
        }]
    }).data("kendoGrid");
    

    工具提示:

    var currentDataItem;
    var toolTip = $('#grid').kendoTooltip({
        filter: ".tooltip",
        content: function (e) {
            var row = $(e.target).closest("tr");
            currentDataItem = grid.dataItem(row);
            return "<div>Hi, this is a tool tip for id " + currentDataItem.Id + "! <br/> <button class='open'>Open window</button></div>";
        }
    }).data("kendoTooltip");
    

    窗口:

    $(document).on("click", ".open", function () {
        var currentContent = currentDataItem.get("StatusText");
        $("<div>Current status: " + currentContent + "</div>").kendoWindow({
            modal: true
        }).getKendoWindow().center().open();
    });
    

    (demo)

    【讨论】:

    • 当我单击打开按钮时,我可以在窗口中显示行信息吗?并且窗口在网格的同一行中显示“字符串值”(如“某些文本”)?
    • 确定;如您所见,我们已经在工具提示的内容方法中访问了当前行的模型;您需要做的就是将该模型存储在设置窗口的函数可访问的变量中(在演示中,这必须是全局的);我编辑了答案以反映这一点
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-25
    • 2023-02-25
    • 1970-01-01
    • 2014-06-11
    相关资源
    最近更新 更多