This is a migrated thread and some comments may be shown as answers.

checkbox template in grid acts weird when grid is destroyed and repopulated

1 Answer 15 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 29 Nov 2016, 02:42 AM

I have a grid with a checkbox template. When I check a checkbox, and click Edit, I get a popup window, which is expected, when I close the popup window, I destroy the grid and rebind the grid again.

When I go to select another record to edit and check that checkbox, then all of a sudden the checkbox of the very first row gets checked as well, and it doesnt matter which checkbox I check, because it also checks the first rows checkbox

The code I am using is

var vendorGrid,
    CreateVendorGrid = function (newData) {
    $("#Vendor-Grid").kendoGrid({
        dataSource: {
            data: newData
        },
        schema: {
            model: {
                fields: {
                    VendorID: { type: "number" }
                },
            }
        },
        filterable: {
            mode: "row"
        },
        columns: [
            {
                template: "<input name='Selected' class='checkbox' type='checkbox'>",
                width: "30px"
            },
            {
                field: "VendorName",
                title: "Vendor",
                filterable: {
                    cell: {
                        showOperators: false,
                        operator: "contains"
                    }
                }
            },
            {
                field: "Email",
                title: "Email",
                filterable: {
                    cell: {
                        showOperators: false,
                        operator: "contains"
                    }
                }
            },
            {
                field: "Phone",
                title: "Phone",
                filterable: false
            },
            {
                field: "City",
                title: "City",
                filterable: false
            }],
        scrollable: true,
        sortable: true,
        pageable: {
            pageSize: 20
        },
        selectable: "row",
        height: $("#Vendor-Grid").closest(".col-height-full").height()-60,
        change: function (e) {
        }
    }).data("kendoGrid");
}
 
//This to get the data to populate the grid
 
function GetVendorGridData() {
    kendo.ui.progress($("#Vendor-Grid"), true);
    $.ajax({
        type: "GET",
        url: URLParam.GetVendorsForGrid,
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: function (data, textStatus, jqXHR) {
            CreateVendorGrid(data);
            kendo.ui.progress($("#Vendor-Grid"), false);
        }
    });
}
 
//This is part of my script in my popup window for closing the window
 
$("#btnCloseVendorEditor").click(function () {
    RefreshVendorGrid();
    GetVendorGridData();
    CloseTheWindow();
});
 
function RefreshVendorGrid() {
    var theGrid = $('#Vendor-Grid').data('kendoGrid');
    theGrid.destroy();
}

1 Answer, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 29 Nov 2016, 03:10 AM
ok, I have it figured out. I removed the name attribute from the template and now everything works.
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Share this question
or