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

Initialize values in new row for grid with "incell" editing

1 Answer 454 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Clinton Smyth
Top achievements
Rank 1
Clinton Smyth asked on 29 Jun 2014, 12:38 AM
Hi

I have a grid set with editable mode "incell". I have a create button at the top of the grid in the toolbar. When I create a new record, I'd like to initialize the values (i.e. provide defaults) of the new record.

I have tried setting the values of the model in the edit event using:
edit: function(e) {
    if (e.model.isNew()) {
        e.model.QuantityAvailable = 1;
    }
}


Although this presets the value when I activate the field editors by tabbing to these fields, it does not display the value until the cell editor is displayed. This is confusing for the user.

I've also tried setting the text value of the new row's <td> attribute using:
edit: function(e) {
    if (e.model.isNew()) {
        e.model.QuantityAvailable = 1;
        var row = e.container.parent();
        row.find("td:nth-child(2)").text(e.model.QuantityAvailable);
    }
}

This sets the value as desired but for some reason renders the cell un-editable!

How can I provide defaults for the new record the user is creating?

Thanks

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 01 Jul 2014, 06:01 AM
Hello Clinton,

You should be using the set method of the model instead of assigning value. By using the set method the model will be marked as `dirty`, i.e edited.

edit: function(e) {
    if (e.model.isNew()) {
        e.model.set("QuantityAvailable", 1);
    }
}


Regards,
Nikolay Rusev
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
Clinton Smyth
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or