简体   繁体   中英

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

I just want to select Check Box on Icon 'A' click. So how will I find check box control.

<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!");
        }
    }
};

在此处输入图片说明

Why you need checkbox control?

Generally you can get it passing this like

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

You can get checkbox control by $(this) .

Please try with the below code snippet.

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

Let me know if any concern.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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