This is a migrated thread and some comments may be shown as answers.

Custom editor value not being updated

3 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Johannes
Top achievements
Rank 1
Veteran
Johannes asked on 17 Jun 2020, 04:25 AM

I have a grid where I am trying to allow users to Update a Boolean value with a dropdown list. The grid displays correctly, and when I change the value of the dropdown list and click Update, the grid displays the correct value. All the other fields are updated to the new values and sent through to the controller correctly, but the new value set by the custom editor is still the old value.

<script>
   function GridBooleanEditor(container, options) {
    $('<input required name="' + options.field + '"/>')
        .appendTo(container)
        .kendoDropDownList({
            dataSource: {
                data: [
                    { text: "True", value: true },
                    { text: "False", value: false }
                ]
            },
            dataTextField: "text",
            dataValueField: "value",
            valuePrimitive: true
        });
    }
 
    function ClassificationSchemeEnabledTemplate(data) {
        var iconClass = data.IsVisible ? 'k-i-check' : 'k-i-close';
        return '<span class="k-icon ' + iconClass + '"></span>';
    }
</script>
 
<kendo-datasource name="schemeDataSource"
                          type="DataSourceTagHelperType.Ajax"
                          page-size="20" server-operation="true"
                          on-error="DataSourceError">
            <transport>
                <read url="@Url.ActionLink("_ReadSchemes", "ControlPanel")" type="POST" />
                <update url="@Url.Action("_UpdateScheme", "ControlPanel")" type="POST" />
            </transport>
            <schema>
                <model id="FolderID">
                    <fields>
                        <field name="FolderID" type="number"></field>
                        <field name="Name" type="string"></field>
                        <field name="Description" type="string"></field>
                        <field name="IsVisible" type="boolean"></field>
                    </fields>
                </model>
            </schema>
        </kendo-datasource>       
 
        <kendo-grid name="schemegrid" datasource-id="schemeDataSource" style="height:100%;">
            <editable mode="inline" enabled="true" />
            <sortable enabled="true" />
            <pageable button-count="5" refresh="true" page-sizes="new int[] { 5, 10, 20 }">
            </pageable>
            <columns>
                <column field="FolderID" title="Folder ID" hidden="true"></column>
                <column field="Name" title="Name"></column>
                <column field="Description" title="Description"></column>
                <column field="IsVisible" title="Enabled" editor="GridBooleanEditor" template="#=ClassificationSchemeEnabledTemplate(data)#"></column>
                <column>
                    <commands>
                        <column-command name="edit"></column-command>
                    </commands>
                </column>
            </columns>
        </kendo-grid>

3 Answers, 1 is accepted

Sort by
0
Silviya Stoyanova
Telerik team
answered on 19 Jun 2020, 04:00 PM

Hello Johannes,

Thank you for the provided code snippets!

I have prepared a sample project with your code and it seems to work as expected.

Could you please modify the project, so we could examine the faulty behavior you are facing?

Kind Regards,
Silviya Stoyanova
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Johannes
Top achievements
Rank 1
Veteran
answered on 23 Jun 2020, 06:00 AM

This has driven me pretty nuts as all my code was the exact same as yours, besides the Model, which had significantly less properties and methods than mine.

I realised that my issue must be in my model and after having a quick look through it I found the issue to be that IsVisible property was a private set;

I use a method to set the model's "IsVisible" property. Is there any way that I can keep my current setup and have the grid work?

0
Accepted
Silviya Stoyanova
Telerik team
answered on 25 Jun 2020, 04:26 PM

Hello Johannes,

With the additionally provided information, we have updated the sample project.

When a model property is configured with a private set method that means only the instance where it is created has access to modify it. 

Then isVisible property needs to be pass as an additional parameter to the controller in order for the data to be updated.

public ActionResult Folders_Update([DataSourceRequest] DataSourceRequest request, FolderViewModel folder, bool isVisible)
<script>
function sendVisibleValue(e) {
        return {
            isVisible: e.IsVisible
        }
    }
</script>

<update url="@Url.Action("Folders_Update", "Grid")" type="POST" data="sendVisibleValue" />

More information about sending additional data can be found here: https://docs.telerik.com/aspnet-core/html-helpers/data-management/grid/faq#how-can-i-send-values-to-my-action-method-when-binding-the-grid

I hope that would help.

Kind Regards,
Silviya Stoyanova
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Johannes
Top achievements
Rank 1
Veteran
Answers by
Silviya Stoyanova
Telerik team
Johannes
Top achievements
Rank 1
Veteran
Share this question
or