2017-05-25 114 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

也许我不是在解释自己。我想要的是自动进入每个单元格并更改值。之后,我会决定是否点击保存按钮。 –