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

Error adding rows from toolbar while in Manual Excel edit mode

Hello,

I've built a sample based on your documentation that allows excel style editing by clicking in each cell and typing.  This works fine.  I've also added the toolbar that has Add Delete and Edit buttons.  When I click the Add button on the toolbar, the columns appear to be offset and I'm only able to edit the first cell.  I've attached the sample project to this thread.  Please let me know if you have any questions or concerns.

Thanks!




ExpenseTrackerBudget Syncfusion_ed7d48ac.zip

3 Replies

BJ Buddy James December 15, 2012 02:46 AM UTC

I've attached a back up of the database required to run the sample application.

SQL SERVER 2008 Express

Thanks.


DB Back up_a3b47d43.zip


BJ Buddy James December 18, 2012 02:42 AM UTC

I understand that the sample that I provided was rather large but the functionality resided in one view and one controller.  I will provide those both here to make it easier.

The View
@using System.Collections
@using Domain.ExpenseTrackerBudget



@{
    ViewBag.Title = "Index";

}


@(Html.Grid<Expense>("Grid1")
    .Datasource((System.Collections.IEnumerable)ViewData["data"]).ActionMode(ActionMode.JSON)
    .Caption("Expenses")
    .Column(column =>
    {
        column.Add(p => p.DateRecorded).HeaderText("Date Recorded").Format("{0:MM/dd/yyyy}");
        column.Add(p => p.Description).HeaderText("Description");
        column.Add(p => p.TotalAmount).HeaderText("Total Amount").Format("{0:C}");
    })
    .EnablePaging().EnableGrouping()
    .EnableSorting().EnableFiltering()
    .AutoFormat(Skins.Vista)
    .ToolBar(tools => tools.Add(GridToolBarItems.AddNew)// tool bar item for Inserting record
        .Add(GridToolBarItems.Edit)// tool bar item for editing record
        .Add(GridToolBarItems.Delete)// tool bar item for Deleting record
        .Add(GridToolBarItems.Update)// tool bar item for save request
        .Add(GridToolBarItems.Cancel))
    .Mappers(mapper => mapper.SaveAction("BulkSave"))
    .Editing(edit =>
    {
        edit.AllowEdit(true);// set AllowEdit as true to allow the update action
        edit.AllowNew(true);
        edit.AllowDelete(true);
        edit.EditMode(GridEditMode.ManualExcel);//Specify the grid edit mode.
        edit.TimeSpan(3000);
        edit.PrimaryKey(key => key.Add(p => p.Id));   // add primary key to primary key collections
    }))

The controller
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataAcess.ExpenseTrackerBudget;
using Domain.ExpenseTrackerBudget;
using Syncfusion.Mvc.Grid;
using Syncfusion.Mvc.Shared;

namespace ExpenseTrackerBudget.Controllers
{
    public class GridController : Controller
    {

        private ExpenseContext _db = new ExpenseContext();
        private GridEditing _gridEditProperties = new GridEditing();

        /// <summary>
        /// Used for rendering the grid initially.
        /// </summary>
        /// <returns>Veiw page, it displays the Grid</returns>
        public ActionResult Index()
        {
            ViewData["data"] = _db.Expenses.ToList();
            //ViewData["Mode"] = GridMode == null ? GridEditMode.ManualExcel : (GridEditMode)GridMode;
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(PagingParams args)
        {
            IEnumerable data = _db.Expenses.ToList();
            if (args.RequestType == 0)
            {
                ViewData["data"] = data;
                return View();
            }
            else 
                return data.GridJSONActions<Expense>();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult BulkSave([Bind(Prefix = "updatedRecords")]IEnumerable<Expense> orders, [Bind(Prefix = "addedRecords")]IEnumerable<Expense> addRcrds, [Bind(Prefix = "deletedRecords")]IEnumerable<Expense> delRcrds)
        {
            //Repository action method Update used for perform update the records into datasource
            if (orders != null)
                OrderRepository.Update(orders);
            if (addRcrds != null)
                OrderRepository.Add(addRcrds);
            if (delRcrds != null)
            {
                OrderRepository.Delete(delRcrds);
            }

            //After save the records into datasource refresh the grid
            var data = _db.Expenses.ToList();
            return data.GridJSONActions<Expense>();
        }}

    public class OrderRepository
    {
        private static ExpenseContext _db = new ExpenseContext();
        internal static void Delete(IEnumerable<Expense> delRcrds)
        {
            foreach (var expense in delRcrds)
            {
                _db.Expenses.Remove(expense);
                _db.SaveChanges();
            }
        }

        internal static void Update(IEnumerable<Expense> orders)
        {
            foreach (var expense in orders)
            {
                _db.Entry(expense).State = EntityState.Modified;
                _db.SaveChanges();
            }
        }

        internal static void Add(IEnumerable<Expense> addRcrds)
        {
            foreach (var expense in addRcrds)
            {
                expense.Id = Guid.NewGuid();

               // if (expense.IsValid)
                //{
                _db.Expenses.Add(expense);
                _db.SaveChanges();
                //}
            }
        }
    }
}

The grid renders fine but when I click the Add button to add a new row the cells shift over and I'm only able to edit one column.... Please let me know if you have any questions or concerns..



RR Ranjithkumar R G Syncfusion Team December 20, 2012 11:13 AM UTC

Hi Buddy,

 

Thanks for your interest in Syncfusion products.

 

We are unable to reproduce your reported issue with your attached project. We can be able to edit all the newly added cells from the Toolbar. We have prepared a video demonstrating the working of your project and the same can be downloaded from the following link.

 

Please get back to us if we misunderstand your query or for any other concern.

 

Regards,

Ranjithkumar.



video2_4be2639f.zip

Loader.
Live Chat Icon For mobile
Up arrow icon