We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Grid's row content disappear after clicking!

I created a grid with batch editing mode. My problem is when I click on each cell of each row. The content of that row disappears. What's wrong with my code?
Here is my View:
@{
    ViewBag.Title = "GridFeatures";
}
<br />

@(Html.EJ().Grid<InlineEditingWithSyncFusion.Models.BumperPendulumResult>("BumperGrid")
                .Datasource(ds => ds.URL("BatchDataSource").BatchURL("BatchUpdate").Adaptor(AdaptorType.UrlAdaptor))
                .AllowPaging()    /*Paging Enabled*/
                .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch); })
                .ToolbarSettings(toolbar =>
                    {
                        toolbar.ShowToolbar().ToolbarItems(items =>
                        {
                            items.AddTool(ToolBarItems.Add);
                            items.AddTool(ToolBarItems.Edit);
                            items.AddTool(ToolBarItems.Delete);
                            items.AddTool(ToolBarItems.Update);
                            items.AddTool(ToolBarItems.Cancel);
                        });

                    })

        .Columns(col =>
        {
            col.Field("TestTitle").HeaderText("Test Title").EditType(EditingType.Dropdown).TextAlign(TextAlign.Right).Width(110).Add();
            col.Field("TargetSpeed").HeaderText("Target Speed").Width(80).Add();
            col.Field("InitialHeight").HeaderText("Initial Height").TextAlign(TextAlign.Right).Width(75).Add();
            col.Field("ActualSpeedCH1").HeaderText("Actual Speed CH1").TextAlign(TextAlign.Right).EditType(EditingType.Dropdown).Width(75).Add();
            col.Field("ActualSpeedCH2").HeaderText("Actual Speed CH2").TextAlign(TextAlign.Right).Width(80).Add();
            col.Field("VehicleWeightFront").HeaderText("Vehicle Weight Front").EditType(EditingType.Numeric).Width(110).Add();
            col.Field("VehicleWeightRear").HeaderText("Vehicle Weight Rear").EditType(EditingType.Numeric).Width(170).Add();
            col.Field("PendulumWeight").HeaderText("Pendulum Weight").TextAlign(TextAlign.Right).Width(100).Add();

        }))

And this is my Controller:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using InlineEditingWithSyncFusion;
using InlineEditingWithSyncFusion.Models;
using System.Data.SqlClient;
using System.Data;
using Syncfusion.JavaScript.DataSources;
using System.Collections;
namespace InlineEditingWithSyncFusion.Controllers
{
    public class GridController : Controller
    {
        //
        // GET: /Grid/
        public ActionResult GridFeatures()
        {
            return View();
        }

        public ActionResult BatchDataSource(Syncfusion.JavaScript.DataManager dm)
        {
            var context = new ProdScheduler03282015Context();            
            IEnumerable DataSource = context.BumperPendulumResults.ToList();  
            BatchDataResult result = new BatchDataResult();
            DataOperations obj = new DataOperations();
            if (dm.Skip != 0)
            {
                DataSource = obj.PerformSkip(DataSource, dm.Skip);
            }
            if (dm.Take != 0)
            {
                DataSource = obj.PerformTake(DataSource, dm.Take);
            }
            result.result = DataSource;
            result.count = context.BumperPendulumResults.ToList().Count();
            result.value = "Hai";

            return Json(result, JsonRequestBehavior.AllowGet);
        }
        public class BatchDataResult
        {
            public IEnumerable result { get; set; }
            public int count { get; set; }
            public string value { get; set; } //custom property
        }
        public ActionResult BatchUpdate(List<BumperPendulumResult> changed, List<BumperPendulumResult> added, List<BumperPendulumResult> deleted)
        {
            var context = new ProdScheduler03282015Context();
            if (added != null)
                foreach (var temp in added)
                {
                    var addedItem = context.BumperPendulumResults.FirstOrDefault(x => x.Id == temp.Id);
                    context.BumperPendulumResults.Add(addedItem);
                }
            //    OrderRepository.Update(changed);
            if (deleted != null)
                //OrderRepository.Delete(deleted);
                foreach (var temp in deleted)
                {
                    var deletedItem = context.BumperPendulumResults.FirstOrDefault(x => x.Id == temp.Id);
                    context.BumperPendulumResults.Remove(deletedItem);
                }
            if (changed != null)
                foreach (var temp in changed)
                {
                    var updatedItem = context.BumperPendulumResults.FirstOrDefault(x => x.Id == temp.Id);
                    updatedItem.TestTitle = temp.TestTitle;
                    updatedItem.TargetSpeed = temp.TargetSpeed;
                    updatedItem.InitialHeight = temp.InitialHeight;
                    updatedItem.ActualSpeedCH1 = temp.ActualSpeedCH1;
                    updatedItem.ActualSpeedCH2 = temp.ActualSpeedCH2;
                    updatedItem.VehicleWeightFront = temp.VehicleWeightFront;
                    updatedItem.VehicleWeightRear = temp.VehicleWeightRear;
                    updatedItem.PendulumWeight = temp.PendulumWeight;
                }
            //    OrderRepository.Add(added);

            var data = context.BumperPendulumResults.ToList();
            context.SaveChanges();
            return Json(data, JsonRequestBehavior.AllowGet);
        }

    }
}


2 Replies

MI minh April 10, 2015 09:18 PM UTC

It seems like EditType(EditingType.Dropdown) does not work with Batching Editting. When I dont use dropdown list here, everything is working fine but as soon as I replace a textbox by a dropdownlist in a cell, the content in that cell will be gone when I click on it to edit. 


PK Prasanna Kumar Viswanathan Syncfusion Team April 13, 2015 01:49 PM UTC

Hi Minh,

Thanks for using Syncfusion Products.

We have analyzed your code snippet and we suggest you to bind a datasource explicit to the dropdown while using URL Adaptor. In URL Adaptor we retrieve only current page records so we could not bind complete datasource for dropdown. So we suggest you to bind datasource explicitly.

Please find the below code snippet :

@(Html.EJ().Grid<MvcApplication14.OrdersView>("FlatGrid")

.Datasource(ds => ds.URL("BatchDataSource").BatchURL("BatchUpdate").Adaptor(AdaptorType.UrlAdaptor))

.AllowPaging() /*Paging Enabled*/

.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch); })

.ToolbarSettings(toolbar =>

{

toolbar.ShowToolbar().ToolbarItems(items =>

{

items.AddTool(ToolBarItems.Add);

items.AddTool(ToolBarItems.Edit);

items.AddTool(ToolBarItems.Delete);

items.AddTool(ToolBarItems.Update);

items.AddTool(ToolBarItems.Cancel);

});

})

.Columns(col =>

{

col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();

col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();

col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).EditType(EditingType.Dropdown).DataSource((List<object>)ViewData["EmployeeID"]).Width(75).Add();

col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add();

col.Field("OrderDate").HeaderText("Order Date").TextAlign(TextAlign.Right).Width(80).Format("{0:MM/dd/yyyy}").Add();

col.Field("ShipCity").HeaderText("Ship City").Width(110).Add();

}))

--------------------------------------------------------------------------------------------------

public ActionResult GridFeatures()

{

ViewData["EmployeeID"] = EmployeeID;

return View();

}

public List<object> EmployeeID

{

get

{

var employeeID = OrderRepository.GetAllRecords().Select(s => s.EmployeeID).Distinct().ToList();

var EmployeeID = new List<object>();

foreach (var id in employeeID)

{

EmployeeID.Add(new { value = id, text = id });

}

return EmployeeID;

}

}

For your convenience we have created a sample and sample can be downloaded from the below link

Sample Link : http://www.syncfusion.com/downloads/support/forum/118811/Sample-1267489255.zip

Please get back to us if you have any further assistance on this,

Regards,

Prasanna Kumar N.S.V


Loader.
Up arrow icon