weixin_33724059 2016-05-31 16:10 采纳率: 0%
浏览 14

Kendo UI网格保存

I am relatively new to Kendo UI. I have my code setup like this. This basically displays editable grid with dropdowns in each column and Adding another record will add a new row of Dropdowns. Is there anyway i can save all the rows at once rather than updating each row individually? My code is setup like this.

<div class="row">
    <div class="col-md-12 ">
        <h5>Markets:</h5>
        @(Html.Kendo().Grid<ETS_Telerik.Models.AddMarketViewModel>()
            .Name("MarketGrid")
            .Columns(columns =>
            {
                columns.Bound(p => p.Country).ClientTemplate("#: Country.Name #").Width("200px");
                columns.Bound(p => p.State).ClientTemplate("#: State.StateName #").Title("State").Width("200px") ;
                columns.Bound(p => p.Name).Width(200);
                columns.Command(command => { command.Destroy(); });
            })
            .ToolBar(toolbar => toolbar.Create())
            .Editable(editable => editable.Mode(GridEditMode.InCell))
            .DataSource(dataSource => dataSource
                .Ajax()
                    .Model(model =>
                    {
                        model.Id(p => p.ID);
                        model.Field(p => p.Country).DefaultValue(ViewData["defaultCountry"]);
                        model.Field(p => p.State).DefaultValue(ViewData["defaultState"]);
                        model.Field(p => p.Name).DefaultValue(ViewData["defaultName"]);
                    })
                .Create(update => update.Action("CreateEmployee", "User"))
                .Read(read => read.Action("ReadEmployees", "User"))
                .Destroy(del=>del.Action("Delete","User"))
                .Update(update => update.Action("UpdateEmployees", "User")))
                )
    </div>
</div>
  • 写回答

1条回答 默认 最新

  • weixin_33721427 2016-06-01 06:35
    关注

    Using below code you can acheive the whole data update.

    $('#updateall').click(function (){
            var displayedData = $("#your-gridid").data().kendoGrid.dataSource.view();
            var Childfood=[];
            for(var i=0;i<displayedData.length;i++)
            {
                var fooddata = {
                    "ChildId"           :   displayedData[i].ChildId,
                    "MorningFood"       :   $("#MorningFood").val(),
    
                }
                Childfood.push(fooddata);
            }
            Childfood = JSON.stringify({ 'Childfood': Childfood });
            var postData = { Childfood: Childfood};
            $.ajax({
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                type: 'POST',
                url: '/your-controller/method',
                data: Childfood,
                success: function () {
    
                },
                failure: function (response) {
                }
            });
        });
    
    
        [HttpPost]
            public JsonResult Recordallchildfood(List<Childfood> Childfood)
            {
    
            var datalist=Childfood;
            //---------
            //your operation bulk update to sql
            //---------
    
            return Json(returnlist, JsonRequestBehavior.AllowGet);
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度