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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

grid editing / adding boolean value always false after posting

Thread ID:

Created:

Updated:

Platform:

Replies:

129319 Mar 12,2017 02:09 PM UTC Mar 16,2017 01:27 PM UTC ASP.NET MVC 10
loading
Tags: Grid
Heinrich
Asked On March 12, 2017 02:09 PM UTC

Hi There,

Not a massive issue but its taking so much of my time now.

When I edit or add an new row the boolean values returned is always false even if the checkbox has been clicked.

When I edit or add the filter search box does not display in die drop down.

My view:

@(Html.EJ().Grid<Brokers.Models.Appointing>("gridAppointing")
                                    .Datasource(ds => ds.Json((List<Brokers.Models.Appointing>)ViewBag.gridAdvisorDS).UpdateURL("AppointingUpdate")
                                                        .InsertURL("AppointingInsert").RemoveURL("AppointingDelete").Adaptor(AdaptorType.RemoteSaveAdaptor))
                                    .AllowResizeToFit()
                                    .AllowPaging()
                                    .EditSettings(e => { e.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Dialog).ShowDeleteConfirmDialog().AllowEditOnDblClick(false); })
                                    .ClientSideEvents(c => c.ActionComplete("onComplete").ActionBegin("onBegin"))
                                    .ToolbarSettings(toolbar =>
                                    {
                                        toolbar.ShowToolbar().ToolbarItems(items =>
                                        {
                                            items.AddTool(ToolBarItems.Add);
                                            items.AddTool(ToolBarItems.Edit);
                                            items.AddTool(ToolBarItems.Delete);
                                            items.AddTool(ToolBarItems.Search);
                                            items.AddTool(ToolBarItems.ExcelExport);
                                        });
                                    })
                                    .Columns(col =>
                                    {
                                        col.Field("ID").IsIdentity(true).IsPrimaryKey(true).Visible(false).Add();
                                        col.Field("FK_AdvisorID").HeaderText("Advisor").Visible(false).EditType(EditingType.Dropdown).DataSource((IEnumerable<object>)ViewData["AdvisorDS"]).Add();
                                        col.Field("FK_ClientID").HeaderText("Client").Visible(false).EditType(EditingType.Dropdown).DataSource((IEnumerable<object>)ViewData["ClientDS"]).Add();
                                        col.Field("Advisor.Name").HeaderText("Advisor Name").EditType(EditingType.String).Add();
                                        col.Field("Client.Name").HeaderText("Client Name").EditType(EditingType.String).Add();
                                        col.Field("DateForm").HeaderText("Application Date").EditType(EditingType.Datepicker).Add();
                                        col.Field("Disclosed").HeaderText("Is Disclosed").EditType(EditingType.Boolean).Add();
                                        col.Field("Appointed").HeaderText("Is Appointed").EditType(EditingType.Boolean).Add();
                                        col.Field("Letter").HeaderText("Is Letter Sent").EditType(EditingType.Boolean).Add();
                                        col.Field("Transferred").HeaderText("Is Transferred").EditType(EditingType.Boolean).Add();
                                        col.Field("Notes").HeaderText("Notes").EditType(EditingType.String).Add();
                                    })
                                )
                                <script type="text/javascript">
                                    function onCompanyComplete(args) {
                                        if (args.requestType == "beginedit" || args.requestType == "add") {
                                            $('#gridAppointing').data("ejGrid").hideColumns(["FK_AdvisorID", "FK_ClientID"]);
                                            $('#gridAppointing').data("ejGrid").showColumns(["Advisor.Name", "Client.Name"]);

                                            $('#gridAppointingFK_AdvisorID').data("ejDropDownList").option("enableFilterSearch", true)
                                            $('#gridAppointingFK_ClientID').data("ejDropDownList").option("enableFilterSearch", true)
                                        }
                                    }

                                    function onBegin(args) {
                                        if (args.requestType == "beginedit" || args.requestType == "add") {
                                            $('#gridAppointing').data("ejGrid").showColumns(["FK_AdvisorID", "FK_ClientID"]);
                                            $('#gridAppointing').data("ejGrid").hideColumns(["Advisor.Name", "Client.Name"]);
                                        }
                                    }
                                </script>

My controller:

public ActionResult Index()
        {
            var context = new ApplicationDbContext();

            var Advisors = context.Advisors.ToList();
            var AdvisorDS = new List<object>();

            foreach (var item in Advisors)
            {
                AdvisorDS.Add(new { value = item.ID, text = item.Name + " " + item.Surname });
            }

            ViewBag.AdvisorDS = AdvisorDS;

            var Clients = context.Clients.ToList();
            var ClientDS = new List<object>();

            foreach (var item in Clients)
            {
                ClientDS.Add(new { value = item.ID, text = item.Name + " " + item.Surname });
            }

            ViewBag.ClientDS = ClientDS;

            return View();
        }

        public ActionResult AppointingInsert(Appointing value)
        {
            var context = new ApplicationDbContext();

            try
            {
                value.Advisor = context.Advisors.Where(c => c.ID == value.FK_AdvisorID).FirstOrDefault();
                value.Client = context.Clients.Where(c => c.ID == value.FK_ClientID).FirstOrDefault();

                context.Appointings.Add(value);
                context.SaveChanges();
            }
            catch (System.Exception)
            {
                throw;
            }

            return Json(value, JsonRequestBehavior.AllowGet);
        }

        public ActionResult AppointingDelete(int key)
        {
            var context = new ApplicationDbContext();

            context.Appointings.RemoveRange(context.Appointings.Where(c => c.ID == key));
            context.SaveChanges();

            return Json(context.Appointings.Where(c => c.FK_ClientID == key).ToList(), JsonRequestBehavior.AllowGet);
        }

        public ActionResult AppointingUpdate(Appointing value)
        {
            var context = new ApplicationDbContext();

            context.Entry(value).State = System.Data.Entity.EntityState.Modified;
            context.SaveChanges();

            return Json(value, JsonRequestBehavior.AllowGet);
        }

all i need is that the boolean fields will reflect true/false on the insert action, at the moment they are always false.

i got the search filter on the drop down to work on another form, not on this one


Mani Sankar Durai [Syncfusion]
Replied On March 13, 2017 10:42 AM UTC

Hi Heinrich, 

Thanks for contacting Syncfusion support. 

Query 1: When I edit or add the filter search box does not display in die drop down. 
 
We have checked the code example that you provided and found the cause of the issue. Since for the ActionComplete event in grid you have named as onComplete in ClientSideEvents but you set the enableFilterQuery in the function named as onCompanyComplete. So this is the cause of the issue which tends not to show filter search in dropdown. 
Refer the code example. 
@(Html.EJ().Grid<MvcApplication.Models.OrdersView>("Edittemplate") 
        .Datasource(ds => ds.Json((IEnumerable<object>)ViewData["Getdata"]).UpdateURL("/Home/Update").InsertURL("/Home/Insert").RemoveURL("/Home/Remove").Adaptor(AdaptorType.RemoteSaveAdaptor)) 
                      ... 
                  .ClientSideEvents(c => c.ActionComplete("onComplete").ActionBegin("onBegin")) 
                   ... 
 
function onComplete(args) { 
        if (args.requestType == "beginedit" || args.requestType == "add") { 
            $('#Edittemplate').data("ejGrid").hideColumns(["EmployeeID"]); 
            $('#Edittemplate').data("ejGrid").showColumns(["Freight"]); 
            $('#EdittemplateEmployeeID').data("ejDropDownList").option("enableFilterSearch", true) 
        } 
    } 

Query 2: When I edit or add an new row the boolean values returned is always false even if the checkbox has been clicked 

We have analyzed your query and we are not able to reproduce the reported issue. When editing or adding it returns the correct Boolean value either true or false in grid. 
Please refer the screenshot below. 
 

 

We have also prepared a sample that can be downloaded from the below link. 
If you still face the issue please get back to us with the following details. 
1.       Share the screenshot video of the issue that you have faced. 
2.       Share the ES version details. 
3.       If possible please reproduce the issue in the above attached sample. 
The provided information will help us to analyze the issue and provide you the response as early as possible 

Regards, 
Manisankar Durai. 


Heinrich
Replied On March 13, 2017 11:36 AM UTC

Thanks for the reply, I have fixed that silly error of mine and changed the onComplete event function to match.

The filter search on the drop down is now fixed but I still get false values on all booleans when i comment out my java script, 
if I dont comment out my java script the add new does not post the new information to the server anymore.

basically what needs to happen on this view is the following:
  • Each appointment is linked to a client and advisor (diffirent models)
  • When the person adds a new record i want them to select from a list of advisors and clients by name but it should save the ID in the FK_Client or FK_advisor fields.
is there a better approach than to hide and show the columns on view / edit / add?

please find attached screenshots.

Attachment: SyncfusionImages_94c3b096.zip

Heinrich
Replied On March 13, 2017 12:43 PM UTC

When I hide the advisor and client name columns on add record, the dialog does not post back, when i unhide them it does..

Heinrich
Replied On March 13, 2017 11:05 PM UTC

Ok so I have managed to sort out almost everything.

there is only one thing remaining.

i get this javascript error after inserting a new record

Uncaught TypeError: n.trim is not a function
    at Object._checkPrimaryValue (ej.web.all.min.js:10)
    at Object._getDataIndex (ej.web.all.min.js:10)
    at Object.sendDataRenderingRequest (ej.web.all.min.js:10)
    at Object._processBindings (ej.web.all.min.js:10)
    at t.DataManager.<anonymous> (ej.web.all.min.js:10)
    at c (jquery?v=DilzeZuJxdbQsfc_JOwsWB4VFDhTPM73urYeggaKdL81:1)
    at Object.fireWith [as resolveWith] (jquery?v=DilzeZuJxdbQsfc_JOwsWB4VFDhTPM73urYeggaKdL81:1)
    at t.DataManager.<anonymous> (ej.web.all.min.js:10)
    at Object.success (ej.web.all.min.js:10)
    at c (jquery?v=DilzeZuJxdbQsfc_JOwsWB4VFDhTPM73urYeggaKdL81:1)

after multiple attempts still cant get this right, some times there are no errors other times there are.

Heinrich
Replied On March 14, 2017 09:37 AM UTC


Mani Sankar Durai [Syncfusion]
Replied On March 14, 2017 02:09 PM UTC

Hi Heinrich, 

We have analyzed your query and we are not able to reproduce the reported issue. We have checked by adding the new record with string column as primary key, but we are unable to reproduce the issue. 
So please share us the following details. 
1.       Share the Essential studio version details that you have used. 
2.       Share the full grid code that you have rendered. 
3.       Share the hosted link of grid rendered. 
4.       If possible please reproduce the reported issue in the previous attached sample. 
The provided information will help us to analyze the issue and provide you the response as early as possible. 

Regards, 
Manisankar Durai. 


Heinrich
Replied On March 14, 2017 03:38 PM UTC

Mani,

Find attached my models, views and other files to see my code.

In the uploaded files there is an advisor and client view and controller.

when i add a new record to email / contact number for the first time the error occurs.

i have updated to the latest version of essential.

ther error : 
Uncaught TypeError: n.trim is not a function
    at Object._checkPrimaryValue (ej.web.all.min.js:10)
    at Object._getDataIndex (ej.web.all.min.js:10)
    at Object.sendDataRenderingRequest (ej.web.all.min.js:10)
    at Object._processBindings (ej.web.all.min.js:10)
    at t.DataManager.<anonymous> (ej.web.all.min.js:10)
    at c (jquery?v=DilzeZuJxdbQsfc_JOwsWB4VFDhTPM73urYeggaKdL81:1)
    at Object.fireWith [as resolveWith] (jquery?v=DilzeZuJxdbQsfc_JOwsWB4VFDhTPM73urYeggaKdL81:1)
    at t.DataManager.<anonymous> (ej.web.all.min.js:10)
    at Object.success (ej.web.all.min.js:10)
    at c (jquery?v=DilzeZuJxdbQsfc_JOwsWB4VFDhTPM73urYeggaKdL81:1)

You can replecate the error by adding a new advisor or client, and then select the newly created, and then adding a new email or contact number. when the new record is added its is saved to the datbase correctly its only after returning from the controller to the view that the js error occurs. when i refresh the page and select the same advisor or client the newly added record is then showing. please get back to me asap.

Attachment: sf_31031df7.zip

Mani Sankar Durai [Syncfusion]
Replied On March 15, 2017 12:17 PM UTC

Hi Heinrich, 

A support incident has been created under your account to track the status of this issue. Please log on to our support website to check for further updates.   
 
 
Regards,   
Manisankar Durai 


Heinrich
Replied On March 15, 2017 12:18 PM UTC

Thanks, are you also getting the error?

Mani Sankar Durai [Syncfusion]
Replied On March 16, 2017 01:27 PM UTC

Hi Heinrich,  
 
 
We have already created the incident under your account. So we request you to follow up the incident for further details. 
  
  
Regards,    
Manisankar Durai  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;