选中kendo网格中的特定复选框

时间:2016-05-19 07:09:36

标签: javascript kendo-ui

我想循环遍历kendo网格的每一行并仅检查特定行的复选框。这是我到目前为止所尝试的。

function LoadControllerGrid(list) {

        $("#controllerGrid1").kendoGrid({
            data Source: {
                type: "json",
                //    contentType: "application/json; charset=utf-8",
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("GetControllerList", "Account"))",
                        type: "POST",
                        dataType: "json"
                    },

                },
                schema: {
                    model: {
                        id: "Id",
                        fields: {
                            'Id': { type: "string" },
                            'Name': { type: "string" },
                            'Description': { type: "string" },
                            'URL': { type: "string" },
                        },

                    },
                    data: 'data',
                    total: 'TotalCount'
                },
                complete: function (jqXHR, textStatus) {
                    //     HidePageLoader();

                },
                pageSize: 5,
                serverPaging: true,
                serverSorting: true,
                serverFiltering: true,
                columnMenu: true
            },
            height: 300,
            groupable: false,
            sortable: true,
            filterable: true,
            pageable: {
                refresh: true,
                pageSizes: 5000
            },
            columns: [{ template: '<input type="checkbox" id="#=Id#" class="gridCK" />', width: "35px" },
                      { field: "Description", title: "Actions" }, ]



        });

        var df = list;
        var grid = $("#controllerGrid1").data("kendoGrid");
        grid.tbody.find("input").closest("tr").each(function (index, row) {

            var dataItem = grid.dataItem(row);
            for (var i = 0; i < df.length; i++)
            {

                if (df[i] == dataItem.Id) {

                    $("#controllerGrid1 tbody").find("tr[data-uid=" + dataItem.Id + "]").attr("checked");


        });


    }

任何人都可以解释我做错了什么?并建议是否有其他方法可以做到这一点。提前致谢

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。

 var selected = $("#controllerGrid1 tbody").find("tr[data-uid=" + dataItem.uid + "]");
                        selected
                        .find("td:first input")
                        .attr("checked", true);

在添加上述代码而不是以下代码后,它对我有用,

 $("#controllerGrid1 tbody").find("tr[data-uid=" + dataItem.Id + "]").attr("checked");
相关问题