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
close icon

Add fields to edit dialog

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


8 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team 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 
 



MH Martin Hoyle 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



AS Alan Sangeeth S Syncfusion Team 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 



MH Martin Hoyle 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.


PK Prasanna Kumar Viswanathan Syncfusion Team 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 



PK Prasanna Kumar Viswanathan Syncfusion Team 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 



MH Martin Hoyle July 19, 2016 08:35 PM UTC

Hi

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

Regards

Martin



PK Prasanna Kumar Viswanathan Syncfusion Team July 20, 2016 07:04 AM UTC

Hi Martin, 

We will wait to hear from you. 

Regards, 
Prasanna Kumar N.S.V 


Loader.
Live Chat Icon For mobile
Up arrow icon