Kendo Grid删除所有列

时间:2015-02-09 07:48:46

标签: javascript jquery kendo-grid

我正在使用Kendo Grid(已启用排序)。删除事件工作正常,但一旦我删除了剑道网格中的所有行,再次按列标题,它开始显示所有已删除的数据。任何人都知道我做错了什么

function GetManagePlanData(_data) {

$.each(_data, function (key, value) {

    if (value.Bonus == 'False')
        $('#chkBonusHeader').attr('checked', false);
    else if (value.MeritIncrease == 'False')
        $('#chkMeritIncHeader').attr('checked', false);
});
var isAllBonusSelected = true, isAllMeritSelected = true, isAllStockSelected = true;

$("#tblEligibleEmployees").kendoGrid({
    dataSource: {
        data:_data,
        group: [{ field: "ManagerName" }],// Add manager name here
        schema: {
            model: {
                fields: {
                    ManagerRelationRefID: { type: "string" },
                    EmployeeRelationRefID: { type: "string" },
                    ManagerName: { type: "string" },
                    EmployeeCode: { type: "string" },
                    FullName1: { type: "string" },
                    JoiningDate: { type: "string" },
                    BusinessUnitName: { type: "string" },
                    FTE: { type: "string" },
                    Salary: { type: "string" },
                    HourlyRate:{ type: "string" },
                    EmpStatus: { type: "string" },
                    MeritIncrease: { type: "bool" },
                    Bonus: { type: "bool" },
                    BonusTarget: { type: "double" },
                    Stock: { type: "bool" },
                    BonusBase: { type: "decimal" },
                    Delete : { type: "string" }

                }
            }
        },
        //pageSize: 20
    },
    scrollable: false,
    sortable: true,
    filterable: false,
    groupable:false,
    //pageable: {
    //    input: false,
    //    numeric: false
    //},
    columns: [
        { field: "ManagerName", hidden: true, title: "Manager Name" },//resource required manager name
        { field: "ManagerRelationRefID", hidden: true, template: "<input id=hdnManagerID#=EmployeeRelationRefID# value=#=ManagerRelationRefID# />" },
        { field: "EmployeeRelationRefID", hidden: true, template: "<input id=hdnEmployeeID#=EmployeeRelationRefID# value=#=EmployeeRelationRefID# />" },
        { field: "EmployeeCode", title: key_EmployeeId, width: "90px" },
        { field: "FullName1", title: key_fullname, width: "140px" },
        { field: "JoiningDate", title: key_hiredt, width: "110px" },
        { field: "BusinessUnitName", title: Key_Location, width: "90px" },
        {
            field: "Salary", title: key_Salary, width: "90px", template: FormatSalary
        },
        {
            field: "HourlyRate", title: 'Hourly Rate', width: "90px", template: FormatHourlySalary
        },
        { field: "FTE", title: Key_FTE, width: "80px" },
        { field: "EmpStatus", title: key_status, width: "70px" },
        {
            field: "MeritIncrease", title: key_MeritIncrease, template: ApplyMeritChecks, width: "100px",
            hidden: (isMeritIncrease == 0 ? true : false),
            headerTemplate: '<input type="checkbox" id="chkMeritIncHeader"  >' + key_MeritIncrease + ' </input>',
            sortable:false
        },
        {
            field: "Bonus", title: key_Bonus, template: ApplyBonusChecks, width: "100px",
            hidden : (isBonus==0 ? true:false),
            headerTemplate: '<input type="checkbox" id="chkBonusHeader">' + key_Bonus + ' </input>',
            sortable: false
        },
        { field: "BonusTarget", title: key_BonusTarget, template: FormatBonusTarget, width: "70px",  hidden : (isBonus==0 ? true:false) },
        {
            field: "Stock", title: key_Stock, template: ApplyStockChecks, width: "60px",
            hidden: (isStock == 0 ? true : false),
            headerTemplate: '<input type="checkbox" id="chkStockHeader" /><label>' + key_Stock + '</label>'
        },
        {
            field:"BonusBase",title:"Bonus Base" ,width:"80px",
        template:ApplyBonusBase,
            sortable:false
        },
        {
            field:"Delete",title:"",width :"80px",template:ApplyDelete,sortable:false
        }
    ]


}).data("kendoGrid");
$('.k-grid-header .k-header').css('font-weight', 'bold');
$('.k-header[data-field="Delete"]').css('text-indent', '-9999px');

}


function deleteRow(ID) {
jConfirm2(key_Yes, key_No, key_PlanDeleteMsg, "", function (r) {
    if (r == true) {

        var nxtRow = $('#btndelete-' + ID).parent().parent().next('tr').hasClass("k-grouping-row");
        var prvRow = $('#btndelete-' + ID).parent().parent().prev('tr').hasClass("k-grouping-row");
        var nxtRowlength = $('#btndelete-' + ID).parent().parent().next('tr').length
       // if ((nxtRow || nxtRowlength == 0) && prvRow) {

            //var rowToDelete = $('#btndelete-' + ID).parent().parent().prev('tr');
            var nextRow = $('#btndelete-' + ID).parent().parent().closest('tr');
            var grid = $("#tblEligibleEmployees").data("kendoGrid");
           // grid.removeRow(rowToDelete);
            grid.removeRow(nextRow);

    }
    });
}

让我知道我做错了什么?

2 个答案:

答案 0 :(得分:1)

请在删除记录后尝试刷新kendo网格。以下是代码。

$('#GridName').data('kendoGrid').refresh();

答案 1 :(得分:0)

我们正在从Kendo数据源中删除数据,而不是从数据库中删除数据。我们的工作准则是

if ($('#tblEligibleEmployees').data('kendoGrid').dataSource._data.length == 0) {
            $('#tblEligibleEmployees').data().kendoGrid.destroy();
            return false;
        }

从kendo数据源中获取长度0,销毁剑道网格。