繁体   English   中英

如何在Kendo-grid中查找Cell索引以及如何将dirty属性设置为true

[英]How to find Cell index inside kendo-grid & how to set dirty property as true

我只想选择“ A”图标上的“复选框”。 因此,我将如何找到复选框控件。

<a class="tooltip-top" onclick="GridArchiveAction(#: id #); " title="Archive" ><img src="/Content/images/Archive.png" style="cursor: pointer;"/></a>

file.js

var GridArchiveAction = function (id) {
    if (confirm("Are you sure you want to archive this item?")) {
        var grid = $('#Grid').data("kendoGrid");
        var item = grid.dataSource.get(id);
        var dataRow = grid.dataSource.getByUid(item.uid);
        if (dataRow != undefined) {
            dataRow.addClass("k-state-selected")
                .find(".isLockedchkbx")
                .prop("checked", "checked");

        } else {
            alert("You Must Select A Row To Archive A Record!");
        }
    }
};

在此处输入图片说明

为什么需要复选框控件?

通常你可以像这样通过它

onclick="GridArchiveAction(this, #: id #); "
//OR
var GridArchiveAction = function (this, id);`

您可以通过$(this)获得复选框控件。

请尝试使用以下代码段。

<body>
    <div id="grid"></div>

    <script>
        $(document).ready(function () {
            $("#grid").kendoGrid({
                dataSource: {
                    type: "odata",
                    transport: {
                        read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Customers"
                    },
                    pageSize: 20
                },
                height: 550,
                groupable: true,
                sortable: true,
                pageable: {
                    refresh: true,
                    pageSizes: true,
                    buttonCount: 5
                },
                columns: [{
                    template: "<a class='tooltip-top' onclick='GridArchiveAction(this);' title='Archive' ><img src='http://www.naadsm.org/naadsm/files/common/smallZipFileIcon.png' style='cursor: pointer;'/></a>",
                    field: "ContactName",
                    title: "Contact Name",
                    width: 240
                }, {
                    template: "<input class='isLockedchkbx' type='checkbox' />",
                    field: "ContactTitle",
                    title: "Contact Title"
                }]
            });
        });

        function GridArchiveAction(obj) {
            if (confirm("Are you sure you want to archive this item?")) {
                var grid = $('#grid').data("kendoGrid");
                var row = $(obj).closest("tr");
                $(row).find('.isLockedchkbx').prop("checked", "checked");
            }
        };

    </script>
</body>

让我知道是否有任何问题。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM