2015-02-09 146 views
0

我正在使用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); 

    } 
    }); 
} 

请让我知道我在做什么错我?

+0

尝试重新绑定并在delete.grid.removeRow不刷新网格数据后刷新网格它只刷新网格UI。 $( “#tblEligibleEmployees”)的数据( “kendoGrid”)刷新()。 – Andrea 2015-02-09 18:05:50

回答

1

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

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

由于您试图删除数据源,因此即使对于单个删除也不起作用。尝试删除一行并按列标题,数据将可见。你试图实现的逻辑是错误的。 – 2015-02-10 19:26:49

0

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

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

在从数据源剑道剑道破坏电网得到长度为0。