以编程方式向kendo网格添加一行而不刷新网格? [英] Add a row to kendo grid programmatically without grid refresh?

查看:115
本文介绍了以编程方式向kendo网格添加一行而不刷新网格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有



我想在没有刷新网格的按钮点击(或任何事件)的情况下在kendo网格中添加行。



我尝试了一些代码但是,(在最后一行点击一行创建一行)



Dear all

I would like to add row in kendo grid on button click (Or any Event ) without refresh grid .

I try some code but , (Cretate a row on last row click )

<div class="col-lg-12">

        @(Html.Kendo().Grid<dbBMC>()
              .Name("grid")
              .Columns(column =>
              {
                  column.Bound(e => e.TaxName).ClientTemplate(
                      @Html.DropDownListFor(model => model.ControlBillMastersupport.TaxName,
                      new SelectList(ViewBag.CCAName, "text", "value"), "---  Select ---", new { @class = "form-control", @id = "taxname"  }).ToString()).Title("TaxName");

                  column.Bound("").Title("Equal");
                  column.Bound(e => e.Value).Title("value");

                  column.Bound(e => e.Sign).ClientTemplate(
                      @Html.DropDownListFor(model => model.ControlBillMastersupport.Sign, 
                      new SelectList(ViewBag.typesign), "---  Select ---", new { @class = "form-control ", @id = "typesign" }).ToString()
                      ).Title("Type");//bind DDL  with help of View Bag 

                  column.Bound(e => e.Onwhich).ClientTemplate(
                      @Html.DropDownListFor(model => model.ControlBillMastersupport.Onwhich,
                          new SelectList(ViewBag.OnWhichData), "---  Select ---", new
                          {
                              @class = "form-control ",
                              @id = "onwhichdata"
                          }).ToString()).Title("OnWhich");
                  column.Command(command => command.Destroy()).Width(110);
              })
              .ToolBar(toolBar =>
              {
                  // toolBar.Create();
                  //toolBar.Save();
              })
              .Editable(editable => editable.Mode(GridEditMode.InCell))
              .Pageable()
              .Sortable()
              .Scrollable()
              .HtmlAttributes(new { style = "height:330px;" })
              .DataSource(dataSource => dataSource
                  .Ajax()
                  .Batch(true)
                  .ServerOperation(false)
                  .Events(events => events.Error("error_handler"))
                  .Model(model =>
                  {
                      model.Id(p => p.BillMasterID2);
                      model.Field(p => p.TaxName).Editable(false);
                      model.Field(p => p.Sign).Editable(false);
                      model.Field(p => p.Onwhich).Editable(false);
                      model.Field(p => p.TaxName).DefaultValue(
                          ViewData["Category"] as ZEN_ERP_FIN_BillMaster2);
                  })
                  .PageSize(20)
                  .Read(read => read.Action("Getdata", "BillMaster"))

                  .Create(create => create.Action("EditingCustom_Create", "BillMaster"))
                  .Update(update => update.Action("EditingCustom_Update", "Grid"))

              )
              )

        <script type="text/javascript">

            function error_handler(e) {
                if (e.errors) {
                    var message = "Errors:\n";
                    $.each(e.errors, function (key, value) {
                        if ('errors' in value) {
                            $.each(value.errors, function () {
                                message += this + "\n";
                            });
                        }
                    });
                    alert(message);
                }
            }
           
                $(".k-grid-content").append('<tr id="clickhere"  width="400" width="200"><td width="400"></td></tr>'); //Append row in grid and generate a row on this row click 

                $("#clickhere").click(DoubleClickAction);
                function DoubleClickAction() {

                    var grid = $("#grid").data("kendoGrid");//Generate a Row 
                    grid.addRow();
                    }




            });

        </script>
    </div>







填充组合框的控制器代码




Controller code for fill combobox

         public void OnWhichData()
        {

            List<string> Onwhichdata = new List<string>();
            Onwhichdata.Add("Assembaly  Value");
            Onwhichdata.Add("Basic Amount");
            Onwhichdata.Add("Quantity");

            IEnumerable<string> data = Onwhichdata.ToList();
            ViewBag.OnWhichData = data;


        }

        [HttpGet]
        public void Typesign()
        {
            List<string> Typesign = new List<string>();
            Typesign.Add("+");
            Typesign.Add("-");
            Typesign.Add("*");
            Typesign.Add("/");
            Typesign.Add("%");
            IEnumerable<string> sign = Typesign.ToList();
            ViewBag.typesign = sign;



        }

        public ActionResult Create()
        {
           Typesign();
            OnWhichData();
            ViewBag.CCAName = new SelectList(connect.dbAMC, "CCAName", "CAID");
            return View();
        }//connect is Entity Name and dbAMC is Table name 

</pre>

推荐答案

.each(e .errors, function (键,值){
if ' errors' in value){
.each(e.errors, function (key, value) { if ('errors' in value) {


.each(value.errors, function (){
message + = this + \ n;
});
}
});
alert(message);
}
}
.each(value.errors, function () { message += this + "\n"; }); } }); alert(message); } }


。k- grid-content)。append(' < tr id =clickherewidth =400 width =200>< td width =400>< / td>< / tr>'); // 在网格中追加行并在此行上生成一行单击
(".k-grid-content").append('<tr id="clickhere" width="400" width="200"><td width="400"></td></tr>'); //Append row in grid and generate a row on this row click


这篇关于以编程方式向kendo网格添加一行而不刷新网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆