Click here to Skip to main content
14,640,679 members
Rate this:
Please Sign up or sign in to vote.
See more:
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>
Posted
Updated 26-May-15 22:29pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100