簡體   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