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

Unable to reset the edited field to its Original value

1 Answer 98 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
nischal
Top achievements
Rank 1
nischal asked on 08 Jan 2016, 11:01 AM

When i edit the end date field and set to the some new date, onSave it does not retain its original value using .set method,

Or any other field for that case, if i edit and onSave if i try set the old value It will not set , (will not reflect in the UI)

 

  $scope.ganttOptions = {

          dataSource: $scope.ganttDataSource,
          dependencies: $scope.ganttDataDependency,
          columns: [
            { field: 'id', title: "Task ID", width: 50, sortable: true},
            { field: "title", title: "Title", width: 100, sortable: true, editable: true },
            { field: "days", title: "Duration", type: "number", width: 50, editable: true},
            { field: 'start', title: "Start", sortable: true, format: "{0:MM/dd/yyyy}", width: 100, editable: true },
            { field: 'end', title: "End", sortable: true, format: "{0:MM/dd/yyyy}", width: 100, editable: true },             
            { field: 'percentComplete', title: '%', width: 50, editable: true},
          ],
           views: [
                    "day",
                    "week",
                    { type: "month", selected: true },
                ],
          add: onAdd,
          edit: onEdit,
          cancel: onCancel,
          save: onSave, 
     };    

//Scenario 1

function onSave(e){  

     if(e.values.end != undefined){

          //Few code here, based on conditions and new values that i get

          //In the end i set the end date to its original value 

         //This does not work

          e.task.set("end", e.task.end);    //e.task.set("end", new Date("03/16/2016"));

     }

//Scenario 2

function onSave(e){

   if(e.value.end != undefined){

     //This way it works, cus edited field is end date and some value is set to days field. 

      e.task.set("days", 12);

   }

}

1 Answer, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 12 Jan 2016, 11:21 AM
Hi,

The reason for the experienced behavior is the following. When a task is updated the values from the event argument are applied to the task fields, so in order to restore a particular field then the e.values object should be altered as shown below:
function onSave(e) {
    if (e.values.end != undefined) {
        e.values.end = e.task.end;
    }
}


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