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

The value wasn't applied to the grid in a condition.

1 Answer 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
yuichi
Top achievements
Rank 1
yuichi asked on 25 Jan 2016, 12:36 AM

I need to set a value in inactive row.
However, If the active row is in edit mode, the value doesn't applies to the grid.

Please check following operation and code. 
Case 1 (expected case): 
 ・operation
   ①Click first record's "attribute" cell.(change to edit mode)
   ②In browser console, below command execute.
     var item = $("#grid").data("kendoGrid").dataSource.at(0);
     item.set("attribute", "123");
 ・result
     first record's "attribute" value is changed from "foo" to "123".

Case 2 (unexpected case): 
 ・operation
   ①Click second record's "attribute" cell.(change to edit mode)
   ②In browser console, below command execute.
     var item = $("#grid").data("kendoGrid").dataSource.at(0);
     item.set("attribute", "123");
 ・result
     first record's "attribute" value isn't changed.

     (The value of the model has been changed. But it does not apply to the grid.)

 following is test code:

<!DOCTYPE html>
<html>
<head>
    <title>KendoUI Test Page</title>
      
  
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
    <div id="grid"></div>
    <script>
    function readonlyEditor(container, options) {
        container.text(options.model[options.field]);
    }
      
    var dataSource = new kendo.data.DataSource({
        data: [
            { id: 1, item: "Item1", attribute: "foo" },
            { id: 2, item: "Item2", attribute: "bar" }
        ],
        schema: {
            model: {
                id: "id",
                fields: {
                    id: { type: "number" },
                    item: { type: "string" },
                    attribute: { type: "string"}
                }
            }
        }
    });
  
    $("#grid").kendoGrid({
        dataSource: dataSource,
        columns: [
            { field: "item"},
            { field: "attribute", editor:readonlyEditor }
        ],
        editable: true,
    });
      
    </script>
</body>
</html>


what should I do? If I want to apply the value of the model to the grid in case 2.

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 27 Jan 2016, 09:36 AM

Hello yuichi,

 

The reason for this behavior is that the entire grid is not refreshed when a field of the model is changed. Otherwise the edit form will be lost (the editing container). 

 

In the incell edit mode only the current editing row is repainted, so the attribute value is changed. 

In order to achieve this behavior the refresh method of the Kendo UI Grid should be called after the edit is completed (since the model is changed, but the grid is not refreshed while in edit mode).  

 

Regards,
Boyan Dimitrov
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
yuichi
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or