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

Dropdown grid inline editing

Hello Syncfusion Team,
I have some problem with inline-editing in grid control.

This is a section of my code (View):

@(Html.EJ().Grid<Ponteggio_New>
            ("tbListaPonteggi")
            .Datasource(ds => ds.URL(Url.Action("getListaPonteggi")).Adaptor(AdaptorType.UrlAdaptor).UpdateURL(Url.Action("Modifica")))
            .EditSettings(edit => { edit.AllowEditing(); })
            .Columns(col =>
            {

                col.Field("id_ponteggio").IsPrimaryKey(true).Add();
                col.Field("id_server").Add();

                col.Field("Impianto.Nome")
                .HeaderText("Impianto")
                 .EditType(EditingType.Dropdown)
                .TextAlign(TextAlign.Center)
                .Width(150)
                .Add();

            })
        )


These are the classes:

public class Ponteggio_New
    {
        [Key]
        public int id_ponteggio { get; set; }
        public string id_server { get; set; }
        public Impianto Impianto { get; set; }
    }

    public class Impianto
    {
        [Key]
        public int id_impianto { get; set; }
        public string Nome { get; set; }
    }

I want to edit the Impianto field in the grid with a dropdown.

So my first question is: Why in this example isn't needed to specify the ShipCity datasource for dropdown and how can achive this in my code?

However, if a specify a datasource for the Impianto field, I obtain the correct result:

col.Field("Impianto.Nome")
                .HeaderText("Impianto")
                .TextAlign(TextAlign.Center)
                .EditType(EditingType.Dropdown)
                .DataSource((IEnumerable<DropDownValuePair>)ViewBag.listaImpianti) 
                .Width(150)
                .Add();

Where IEnumerable<DropDownValuePair> is mapped using: value = id_impianto and text = Nome
public class DropDownValuePair {
        [Key]
        public int value { get; set; }
        public string text { get; set; }
}


When I try to edit the field it shows the correct list of Impianto.

BUT, the selected value is changed with the first value of the datasource. For example, if the value selected is Impianto5, when I edit the cell it becomes Impianto1.

How can I solve this problem? And what about null value on dropdown?

Thank you in advance.


8 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team November 9, 2015 12:19 PM UTC

Hi Omar,

Query #1: the selected value is changed with the first value of the datasource when explicitly binding datasource to Grid Column.

We are unable to reproduce the issue at our end. We have prepared a sample with above requirement that can be downloaded from the below location. In the sample, Grid is placed in views/Grid/.

@(Html.EJ().Grid<Object>("FlatGrid")

            .Datasource(ds => { ds.URL("/Grid/DataSource").Adaptor(AdaptorType.UrlAdaptor).UpdateURL("/Grid/Update"); })

        .AllowScrolling()

         .AllowPaging()

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

         .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").DataSource(ViewBag.dataSource2).EditType(EditingType.Dropdown).TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("Freight").HeaderText("Freight").Add();
        }))

public ActionResult GridFeatures()

        {

            List<dropDown> list = new List<dropDown>();

            list.Add(new dropDown(1, "1"));

            list.Add(new dropDown(2, "2"));

            . . .  .

            list.Add(new dropDown(9, "9"));

            ViewBag.dataSource2 = list;

            return View();

        }

        public ActionResult DataSource(DataManager dm)

        {


            IEnumerable DataSource = OrderRepository.GetAllRecords();

            . . .  . .

            return Json(result, JsonRequestBehavior.AllowGet);

        }

        public class dropDown {

            public string text { get; set; }

            public int value { get; set; }

            public dropDown() { }

            public dropDown(int val, string txt) {

                this.text = txt;

                this.value = val;

            }
        }


We have prepared a sample with above requirement that can be downloaded from the below location. In the sample, Grid is placed in views/Grid/.

Sample: http://www.syncfusion.com/downloads/support/forum/121064/ze/MvcApplication41984734187

If you are still facing the difficulties, please share the following which will help to analyze the issue.

1)      Essential Studio Version
2)      Stack trace for the error(if any)
3)      Please replicate the issue in above sample and send back, if possible.

Query #2: what about null value on dropdown?

In our online sample, the local datasource has been bound for the Grid and in our Grid source we fetch dataSource for Dropdown from Grid DataSource. But while binding remote-date we need to return datasource for Dropdown from the server-side using “PerformSelect” method of DataOperations Class.

https://www.syncfusion.com/kb/4300/server-side-api-for-datamanager-operations

But we are having some issues with this type of databinding for the dropdown. So we have logged the defect report “Server side handling of DropDown Edit dataSource is not recogonised”, which will be available on November 30, 2015 and this fix will be included in our Volume 3 Service Pack 2,2015 release which is expected to be roll out at the end of month November, 2015.

Regards,
Seeni Sakthi Kumar S.


OM Omar Muscatello November 9, 2015 06:02 PM UTC

Thank you Seeni Sakthi Kumar Seeni Raj.
It works. But my aim is to display the text field of dropdown, not the value.

I changed the example which you submited as below:

 List<dropDown> list = new List<dropDown>();

         list.Add(new dropDown(1, "1 - First"));
        list.Add(new dropDown(2, "2 - Second"));
        . . .  .
The text field is displayed in the dropdown when the row is in edit-mode. But when it is in display-mode it shows the value field.
Reported to my problem, I want to display the Nome field of Impianto, not the id_impianto field.

Essential studio version: 13.3.0.7

Thank again




AS Alan Sangeeth S Syncfusion Team November 10, 2015 07:59 AM UTC

Hi Omar,
 
We suggest you to use of ForeignKey Column concept in our Grid control to meet your requirement. Please refer to the following Online sample and documentation.
 
Online Sample: http://mvc.syncfusion.com/demos/web/grid/foreignkeycolumn
Documentation: http://help.syncfusion.com/aspnetmvc/grid/columns#foreign-key-columns
 
Regards,
Alan Sangeeth S


OM Omar Muscatello November 10, 2015 12:03 PM UTC

Thank you Alan Sangeeth S.
I switched to foreign key. Now it works correctly, but is random. See the video attached please.

This is the code I'm using:

        //Impianto, dropdown
        col.Field("ImpiantoID").HeaderText("Impianto")
        .ForeignKeyField("id_impianto")
        .ForeignKeyValue("Nome")
        .DataSource((IEnumerable<Impianto>)ViewBag.listaImpianti)
        .EditType(EditingType.Dropdown)
        .TextAlign(TextAlign.Center)
        .Width(150)
        .Add();

        //Zona, dropdown
        col.Field("ZonaID").HeaderText("Zona")
        .ForeignKeyField("id_zona")
        .ForeignKeyValue("Nome")
        .DataSource((IEnumerable<Zona>)ViewBag.listaZone)
        .EditType(EditingType.Dropdown)
        .TextAlign(TextAlign.Center)
        .Width(100)
        .Add();

As you can see in the video attached, sometimes the value selected is correct, and sometimes not.

I created a test project to check if is the same with a static datasource (instead of database) and it works correctly. The class used in the test project are the same of the originale project.
What could cause this problem?
Some other column of the table?


OM Omar Muscatello replied to Omar Muscatello November 10, 2015 12:04 PM UTC

Thank you Alan Sangeeth S.
I switched to foreign key. Now it works correctly, but is random. See the video attached please.

This is the code I'm using:

        //Impianto, dropdown
        col.Field("ImpiantoID").HeaderText("Impianto")
        .ForeignKeyField("id_impianto")
        .ForeignKeyValue("Nome")
        .DataSource((IEnumerable<Impianto>)ViewBag.listaImpianti)
        .EditType(EditingType.Dropdown)
        .TextAlign(TextAlign.Center)
        .Width(150)
        .Add();

        //Zona, dropdown
        col.Field("ZonaID").HeaderText("Zona")
        .ForeignKeyField("id_zona")
        .ForeignKeyValue("Nome")
        .DataSource((IEnumerable<Zona>)ViewBag.listaZone)
        .EditType(EditingType.Dropdown)
        .TextAlign(TextAlign.Center)
        .Width(100)
        .Add();

As you can see in the video attached, sometimes the value selected is correct, and sometimes not.

I created a test project to check if is the same with a static datasource (instead of database) and it works correctly. The class used in the test project are the same of the originale project.
What could cause this problem?
Some other column of the table?

Video attached

Attachment: Video_10e7d48b.zip


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team November 11, 2015 10:33 AM UTC

Hi Omar,

We are unable to reproduce the issue at our end after rendering a foreign column. We have given the dataSource as metaobject as well as business objects.

List<object> list = new List<object>(); //metaobject

            list.Add(new { EmployeeID1 = 1, Name = "John" });

            list.Add(new { EmployeeID1 = 2, Name = "11/2" });

             . .  .  ..

            list.Add(new { EmployeeID1 = 9, Name = "Joh8" });

            ViewBag.dataSource2 = list;

            List<dropDown> drop = new List<dropDown>(); //Business objects

            drop.Add(new dropDown(1, "Johh"));

            . . . . .

            drop.Add(new dropDown(9, "Johh8"));
            ViewBag.dataSource3 = drop;


We requesting you to share the following details to analyze the issue and provide an appropriate solution.

1)      Datasource bound to the dropdown columns
2)      Code example of Grid
3)      Stack trace of the browser console(if any error)
4)      You could also replicate the issue in the attached sample also.

Also, we have attached the modified sample which can be downloaded from the following location.

Sample: http://www.syncfusion.com/downloads/support/forum/121064/ze/MvcApplication41555998879

Query: what about null value on dropdown?

We considered this as a bug, “Server side handling of DropDown Edit dataSource is not recogonised” and 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.

https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents

Regards,
Seeni Sakthi Kumar S.


OM Omar Muscatello November 11, 2015 12:25 PM UTC

Thank you Seeni Sakthi Kumar Seeni Raj.

I found the problem. Check the attached example based on yours.

The problem occurs when I use two or more dropdown.

In the example, note that EmployeeID is different from AgeID (expect third employee).
When you try to edit the row, the EmployeeID becomes the same of AgeID. Please, see te video in the attach.

I hope I explained myself and sorry for my bad english

Attachment: MvcApplication41555998879__edited_6742001a.zip


GV Gowthami V Syncfusion Team November 12, 2015 01:03 PM UTC

Hi Omar,
 
We have an issue “While using multiple Dropdowns incorrect value showed after saving" and created a new support incident under your account.

 Please log on to our support website to check for further updates.

https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents
 
Regards,
Gowthami V.


Loader.
Live Chat Icon For mobile
Up arrow icon