2015-02-09 113 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。