2017-05-25 166 views
0

我把這個Kendo UI網格綁定到一張桌子上。此網格具有活動的批量編輯功能。這意味着我可以直接在網格單元上更改值並保存。批量更新Kendo UI Grid動態更改值

我想完成的是通過每行更改客戶端一些列中的顯示值來運行循環,然後點擊保存按鈕。

這是我在我的網格:

@(Html.Kendo().Grid<TokenEncrypt.Models.SellerEntity>() 
    .Name("grid") 

    .Columns(columns => 
    { 
     columns.Bound(c => c.Name); 
     columns.Bound(c => c.EntityId); 
     columns.Bound(c => c.SellerEntityTypeId); 
     columns.Bound(c => c.CompanyId); 
     columns.Bound(c => c.IsActive); 
     columns.Bound(c => c.AwsAccessKeyId); 
     columns.Bound(c => c.SecretAccessKey); 
    }) 
    .HtmlAttributes(new { style = "height: 500px;" }) 
    .Scrollable()  
    .Editable(editable => editable.Mode(GridEditMode.InCell)) 
    .ToolBar(toolbar => 
    { 
     toolbar.Save(); 
    }) 


    .DataSource(dataSource => dataSource 
     .Ajax() 
     .Read(read => read.Action("SellerEntities_Read", "Grid")) 
     .Update(update => update.Action("SellerEntities_Ubdate", "Grid")) 
     .Batch(true) 
     .Model(model => 

     { 
      model.Id(c => c.EntityId); 
     } 
    ) 

    ) 

     ) 

這是我在我的循環:(我沒有線索如何刪除值,並把在網格單元新一千萬。

function gridChange() { 

    var grid = $("#grid").data("kendoGrid"); 
    grid.dataSource.read(); 
    var count = grid.dataSource.total(); 
    $("#countElement").html('Encrypting ' + count + ' Lines'); 

    // get data from the grid 
    var gridData = $("#grid").data().kendoGrid.dataSource.view(); 
    var grid = $("#grid").data("kendoGrid"); 
    // loop rows 
    for (i = 0; i < count; i++) { 

     str = gridData[i].EntityId; 
     EntityIdhash = CryptoJS.SHA256(str); 

     // remove old value 
     // enter new value 

     console.log('EntityId: ' + gridData[i].EntityId + '\n'); 
     console.log('EntityId encrypted: ' + EntityIdhash + '\n'); 

    } 

}; 
+1

好了,據我所知,您更改網格那麼你一定要牛逼o點擊「保存」按鈕,並讓它在您更改的每一行中循環運行並保存這些更改? – Keith

+0

是@Keith,你有這個權利 –

+0

你使用內聯編輯還是你必須點擊一個按鈕來編輯行? – Keith

回答

1

這裏是你可以做什麼(沒有看到任何HTML):

$('#save').on('click', function() { 
    success(); 
}) 

function success() { 
    var storedValues = []; 
    var gridData = $("#grid").data().kendoGrid.dataSource.data(); 
    for (var i = 0; i < gridData.length; i++) { 
     if (gridData[i].EntityId) { 
      storedValues.push({ 
       cellValue: gridData[i].EntityId, 
      }); 
     } 
    } 
    var inputData = { yourVariable: JSON.stringify(storedValues) }; 
    $.ajax({ 
     cache: false, 
     type: 'POST', 
     url: "/YourController/Here", 
     data: inputData 
    }).done(function (data) { 
     // success here 
      $('#grid').data('kendoGrid').refresh(); 
     } 
    }); 
}; 
+0

在這種情況下,您可以更改這些值並將它們存儲在數組中以便在json中發佈。我想要的結果是在網格中變化,之後我將決定是否保存。這是批量編輯行爲。附:沒有HTML我正在使用剃刀語法來創建網格。 –

+0

默認情況下,editable:true可以讓您進行基於字符串或數字的單元格編輯,您可以立即更改,並在關注單元格時保留新元素。這是不是應該如此行事?當你編輯一個單元格時會發生什麼? – Keith

+0

也許我不是在解釋自己。我想要的是自動進入每個單元格並更改值。之後,我會決定是否點擊保存按鈕。 –