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

Update dataSource on Radiobutton Change

1 Answer 668 Views
Grid
This is a migrated thread and some comments may be shown as answers.
crazy05
Top achievements
Rank 1
crazy05 asked on 10 Mar 2015, 03:48 PM
Hello,

My Kendo Grid Template is below. If user changes radio button, I want to update dataSource. How can I do this ?

<script type="text/x-kendo-template" id="SiteTemplate">
    <tr class='k-alt'>
        <td>#: Name #</td>
        <td>
            #if(AccessType == 'Read') { #
            <input type="radio" name="#: Id #" class="read" checked="checked" />
            #}else{#
            <input type="radio" name="#: Id #" class="read" />
            # } #
        </td>
        <td>
            #if(AccessType == 'ReadWrite') { #
            <input type="radio" name="#: Id #" class="readWrite" checked="checked" />
            #}else{#
            <input type="radio" name="#: Id #" class="readWrite"/>
            # } #
        </td>
        <td>
            #if(AccessType == 'None') { #
            <input type="radio" name="#: Id #" class="None" checked="checked" />
            #}else{#
            <input type="radio" name="#: Id #" class="None"  />
            # } #
        </td>
    </tr>
</script>

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 12 Mar 2015, 11:01 AM
Hello,

Basically, you should handle the radio buttons click or change event and set the value to the model
$("#grid").on("click", ":radio", function() {
    var grid = $("#grid").data("kendoGrid");
    var radio = $(this);
    var item = grid.dataItem(radio.closest("tr"));
    var value;
    if (radio.hasClass("read")) {
        value = "Read";
    } else if (radio.hasClass("readWrite")) {
        value = "ReadWrite";
    } else {
        value = "None";
    }
    item.set("AccessType", value);
});

If the grid is bound via source binding then you could also use checked binding for the radio buttons:
<script type="text/x-kendo-template" id="SiteTemplate">
    <tr class='k-alt'>
        <td>#: Name #</td>
        <td>
           <input type="radio" name="#: Id #" value="Read" class="read" data-bind="checked:AccessType" />
        </td>
        <td>
            <input type="radio" name="#: Id #" value="ReadWrite" class="readWrite" data-bind="checked:AccessType" />
        </td>
        <td>
            <input type="radio" name="#: Id #" value="None" class="None" data-bind="checked:AccessType" />
        </td>
    </tr>
</script>


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
crazy05
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or