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

How to check checkbox on dialog template based upon a grid value

Hi

I have a grid with e checkbox column

                        @(Html.EJ().Grid<MyProject.Model.ViewModels.MyViewModel>("MyGrid")
                            .EditSettings(edit =>
                                edit.AllowEditing()
                                .AllowAdding()
                                .AllowDeleting()
                                .EditMode(EditMode.DialogTemplate)
                                .DialogEditorTemplateID("#editTemplate")
                                )
                            .AllowFiltering()
                            .AllowPaging()
                            .AllowSorting()
                            .AllowTextWrap()
                            .Locale("it-IT")
                            .FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
                            .ToolbarSettings(toolbar =>
                            {
                                toolbar.ShowToolbar().ToolbarItems(items =>
                                {
                                    items.AddTool(ToolBarItems.Add);
                                    items.AddTool(ToolBarItems.Edit);
                                    items.AddTool(ToolBarItems.Delete);
                                    items.AddTool(ToolBarItems.Update);
                                    items.AddTool(ToolBarItems.Cancel);
                                });
                            })
                            .Columns(col =>
                            {
                                col.Field("Id").IsPrimaryKey(true).Visible(false).Add();
                                col.Field("Name").HeaderText("Name").HeaderTextAlign(TextAlign.Center).EditType(EditingType.String).ValidationRules(v => v.AddRule("required", true)).Add();
                                col.Field("Active").HeaderText("Active").TextAlign(TextAlign.Center).HeaderTextAlign(TextAlign.Center).EditType(EditingType.Boolean).Add();
                            })
                        )

I use a dialog template to edit data

<script type="text/template" id="editTemplate">
    <table cellspacing="10">
        <tr>
            <td style="text-align:right;">Name:</td>
            <td style="text-align:left;">
                <input id="Name" name="Name" value="{{: Name}}" class="e-field e-ejinputtext valid" style="width:200px;" />
            </td>
            <td>
                <input id="Active" name="Active" value="{{: Active}}" type="checkbox" class="e-field e-ejcheckbox valid" style="width:20px;" />
            </td>
            <td style="text-align:left;">Active</td>
        </tr>
    </table>
</script>

In execution, when i open the dialog to edit data the checkbox is never checked, even if the column in the grid is checked.
What am i doing wrong?
Thank you

3 Replies

BM Balaji Marimuthu Syncfusion Team October 1, 2015 09:53 AM UTC

Hi Fabrizio, 

Thanks for contacting Syncfusion support.

To display the checkbox while editing, please render the template as follows,




<script type="text/template" id="editTemplate">

    <table cellspacing="10">

        <tr>

            <td style="text-align:right;">Name:</td>

            <td style="text-align:left;">

                <input id="Name" name="Name" value="{{: Name}}" class="e-field e-ejinputtext valid" style="width:200px;" />

            </td>

            <td>

                {{if Active}}

                <input id="Active" name="Active" type="checkbox" class="e-field e-ejcheckbox valid" checked="checkbox" style="width:20px;" />

                {{else}}

                <input id="Active" name="Active" type="checkbox" class="e-field e-ejcheckbox valid" style="width:20px;" />

                {{/if}}

            </td>

            <td style="text-align:left;">Active</td>

        </tr>

    </table>

</script>




Please refer to the following sample, 
MvcEJGrid

Regards,
Balaji Marimuthu



IK Ismail Karakaya June 28, 2016 07:17 PM UTC

 
you can use "checked" instead of "value ". It worked for me

<input id="Active" name="Active" value="{{: Active}}" type="checkbox" class="e-field e-ejcheckbox valid" style="width:20px;" />

<input id="Active" name="Active" checked="{{: Active}}" type="checkbox" class="e-field e-ejcheckbox valid" style="width:20px;" />


KK Karthick Kuppusamy Syncfusion Team June 29, 2016 04:01 AM UTC

Hi Fabrizio, 
 
Thanks for the update. 
 
We are happy to hear that your requirement is achieved. 
 
Regards, 
K.Karthick. 


Loader.
Live Chat Icon For mobile
Up arrow icon