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

Add fields to edit dialog

Thread ID:

Created:

Updated:

Platform:

Replies:

124985 Jul 12,2016 07:49 PM UTC Jul 20,2016 07:04 AM UTC ASP.NET MVC 8
loading
Tags: Grid
Martin Hoyle
Asked On July 12, 2016 07:49 PM UTC

Hi

I am using a grid with Dialog editing enabled.
All works fine but I have a need to add additional fields from my model to the edit Dialog.
These fields are not displayed in the grid. Is this possible?


Regards

Martin


Prasanna Kumar Viswanathan [Syncfusion]
Replied On July 13, 2016 09:04 AM UTC

Hi Martin, 

Thanks for contacting Syncfusion support. 

Yes, it is possible to add additional fields to the edit dialog. we have created a sample in which we used editmode as dialogTemplate to achieve your requirement. Using this template support, you can edit the fields that are unbound to grid columns.   

In this sample, we have added the ShipName and ShipAddress to the edit dialog.    

Find the code example and sample. 


@(Html.EJ().Grid<object>("Editing") 
        .Datasource((IEnumerable<object>)ViewBag.dataSource) 
            .EditSettings(edit => edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.DialogTemplate).DialogEditorTemplateID("#template")) 
        --------------------------------------------------- 
       .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("ShipCountry").HeaderText("Ship Country").EditType(EditingType.Dropdown).TextAlign(TextAlign.Right).Width(75).Add(); 
            col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add(); 
            col.Field("ShipCity").HeaderText("Ship City").Width(90).Add(); 
        }) 
) 

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

<script type="text/template" id="template"> 
        <b>Order Details</b> 
        <table cellspacing="10"> 
            -------------------------------------- 
               <td style="text-align: right;">Ship Name 
                </td> 
                <td style="text-align: left"> 
                    <input id="ShipName" name="ShipName" value="{{: ShipName}}" class="e-field e-ejinputtext valid" 
                        style="width: 116px; height: 28px" /> 
                </td> 
            </tr> 
            <tr> 
                <td style="text-align: right;">Ship Address 
                </td> 
                <td style="text-align: left"> 
                    <textarea id="ShipAddress" name="ShipAddress" class="e-ejinputtext" value="{{: ShipAddress}}">{{: ShipAddress}}</textarea> 
                </td> 
            </tr> 
        </table> 
    </script> 



Refer to the Help document for DialogTemplate.   
 

Regards, 
Prasanna Kumar N.S.V 
 


Martin Hoyle
Replied On July 13, 2016 11:11 AM UTC

Hi

Thanks for that - I was hoping for a much simpler solution.
The amount of javascript required seems excessive and effectively duplicates an existing form to edit this particular model.
Its a shame that the mode of "How to Add Controls in Dialog Template – Server Mode" used in your MVC classic package was not maintained.


Regards


Martin


Alan Sangeeth S [Syncfusion]
Replied On July 14, 2016 11:56 AM UTC

Hi Martin, 

The Syncfusion Essential Studio for ASP.NET MVC is a set of server-side wrappers which is empowered by Essential JavaScript. The control declaration defined at the server side and the actual rendering and manipulations happens on the client side.  

Since client-side operations are faster than server-side, our grid behavior is that the edit form template will be defined and used from client-side itself. 

If you would like to render the edit form template from server-side (using partial view), then please get back to us so that we could modify the solution based on it. 

Regards,
Alan Sangeeth S 


Martin Hoyle
Replied On July 14, 2016 12:01 PM UTC

Hi

I take your point about client-side operations
But in this case it would be useful to be able to render the edit form template from server-side (using partial view), if this is possible ?

Regards

Martin.

Prasanna Kumar Viswanathan [Syncfusion]
Replied On July 18, 2016 12:57 PM UTC

Hi Martin, 

Yes, it is possible to render the edit form template using partial view. In this sample we render the edit form template in the partial view using ajax post.  

Find the code example and sample: 


@(Html.EJ().Grid<EJGrid.Models.EmployeeView>("Editing") 
        .Datasource((IEnumerable<object>)ViewBag.dataSource) 
        .EditSettings(edit => edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.DialogTemplate).DialogEditorTemplateID("#template")) 
        ------------------------------- 
       .AllowPaging() 
        .Columns(col => 
        { 
            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(90).Add(); 
            col.Field("EmployeeID").HeaderText("Employee ID").Width(80).Add(); 
            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add(); 
            col.Field("Freight").HeaderText("Freight").Width(80).Add(); 
        }) 
) 
 
@Html.Partial("EditTemplate") 

-------------------------------------------------------------------- 
$.ajax({ 
            url: "/Home/GetData", 
            type: "POST", 
            contentType: "application/json", 
            data: JSON.stringify({ value: records }), 
            success: function (data) { 
                $("#template").html(data);                 
                args.model.prefixIcon != "create" && $("#OrderID").attr("disabled", "disabled"); 
                $($("#template").html()).prependTo($("#GridEditForm"));                
                //ej.widget.init($("#template"));  //initialize the ejwidgets 
            }, 
            error: function (xhr) { 
                alert('error'); 
            } 
        }); 
    } 


Regards, 
Prasanna Kumar N.S.V 


Prasanna Kumar Viswanathan [Syncfusion]
Replied On July 18, 2016 02:38 PM UTC

Hi Martin, 

Please ignore the previous update. 

Yes, it is possible to render the edit form template using partial view. In this sample we render the edit form template in the partial view using ajax post.  

Find the code example and sample: 

@(Html.EJ().Grid<object>("Grid") 
            .Datasource((IEnumerable<object>)ViewBag.data) 
            .AllowPaging() 
            --------------------------------------- 
            .EditSettings(edit => 
            { 
                edit.AllowAdding();//enebled adding 
                edit.AllowDeleting();//enabled deleting 
                edit.AllowEditing();//enabled editing 
                edit.EditMode(EditMode.DialogTemplate);//setting edit mode as dialog such as dialog open on add/edit 
            }) 
            .Columns(col => 
            { 
                    ------------------------- 
            })      
            .ClientSideEvents(eve => eve.ActionComplete("complete"))        
    ) 
-------------------------------------------------------------------- 
$.ajax({ 
            url: "/Home/GetData", 
            type: "POST", 
            contentType: "application/json", 
            data: JSON.stringify({ value: records }), 
            success: function (data) { 
                $("#template").html(data);                 
                args.model.prefixIcon != "create" && $("#OrderID").attr("disabled", "disabled"); 
                $($("#template").html()).prependTo($("#GridEditForm"));                
                //ej.widget.init($("#template"));  //initialize the ejwidgets 
            }, 
            error: function (xhr) { 
                alert('error'); 
            } 
        }); 
    } 


Regards, 
Prasanna Kumar N.S.V 


Martin Hoyle
Replied On July 19, 2016 08:35 PM UTC

Hi

Thanks for the sample I will integrate this technique into my solution.

Regards

Martin


Prasanna Kumar Viswanathan [Syncfusion]
Replied On July 20, 2016 07:04 AM UTC

Hi Martin, 

We will wait to hear from you. 

Regards, 
Prasanna Kumar N.S.V 


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

;