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

Assign values to multiple fields in editor function?

1 Answer 370 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cyndie
Top achievements
Rank 1
Cyndie asked on 18 May 2012, 03:31 PM
I have editors setup for a few columns in my grid.  The editors use a dropdown list and data-bind to a value field, which is an id (integer).  This id field is different than the string field used to display the text in that column when it is not in edit mode.  My SQL table needs the lookup id, not the text.  Because of this, when I add a new record, these columns are blank and if I edit a row, the text on those columns does not change unless I refresh the page. To resolve this, I think I need one of two things to happen, but I'm not sure how to do either. 

- The best solution would be to be able to update both fields in the editor function.  The only examples that I see use the data-bind in the input dropdown item to update a single field.  Is there a way to change the value of other fields in the editor function?  Here is one of my editor functions.  How can I populate another field called SecondaryVoltage with the selected data-text-field string from the dropdownlist.
function secondaryVoltageEditor(container, options) {
    $('<input data-text-field="Voltage" data-value-field="id" data-bind="value:SecondaryVoltageID" />')
    .appendTo(container)
    .kendoDropDownList({
        autoBind: false,
        dataSource: voltageDataSource
    });
}


- The other less desirable solution would be to refresh the grid after a create or update which will lookup the text value associated with the id, but I'm not sure how to do that either.

1 Answer, 1 is accepted

Sort by
0
Cyndie
Top achievements
Rank 1
answered on 18 May 2012, 09:02 PM
I figured this out.  I added the following change function to the dropdownlist within the edit function:

change: function (e) {
                options.model.PrimaryVoltage = this.dataItem().Voltage;
            }
Tags
Grid
Asked by
Cyndie
Top achievements
Rank 1
Answers by
Cyndie
Top achievements
Rank 1
Share this question
or