title: add record function in Kendo UI insert always two rows
body: <p>Thank you so much for your support as always. I have a big problem working with Kendo UI for PHP.
  I am using this javascript code for Kendo UI grid:</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function () {  
  var suffers = [];
  var solvers = [];
  var actions = [];
  
  var dataSource = new kendo.data.DataSource({
  pageSize: 30,
  //data: products,
   transport: {
                //read: "data/fActions.php",
                                          read: "data/fetchActions.php",
                                          update: {url:"data/updateC.php", type:"POST",complete: function (e) {
                                              //alert ("completado");
                                              grid.dataSource.read(); 
                                              grid.refresh();
                                              }},
                                          create: {url:"data/createC.php",type:"POST", complete: function (e) {
                                              //alert ("completado");
                                              grid.dataSource.read(); 
                                              grid.refresh();
                                              }},
                                          destroy: {url:"data/destroyC.php",type:"POST", complete: function (e) {
                                              //alert ("completado");
                                              grid.dataSource.read(); 
                                              grid.refresh();
                                              }}
                                          /*parameterMap: function(options, operation)
                                          {
                                              if (operation == "create" &amp; options.models)
                                              {
                                                  return JSON.stringify({ "action": options.models});
                                              }
                                          }*/
                          },
  autoSync: true,
  batch: true,    
  schema: {
    model: {
      id: "ActionID",
      fields: {
      ActionID: { editable: false, type: "number"},
        DateCreated: { field: "DateCreated", editable:"inline", defaultValue: Date()  },
        SufferID: {field: "SufferID" , editable:"inline", defaultValue: 1 },
        Problem: { validation: { required: true }, editable:"inline", defaultValue: "Write here the problem"  },
        SolverID: { field: "SolverID" , editable:"inline", defaultValue: 1   },
        DateSolved: { field: "DateSolved" , editable:"inline", defaultValue: Date() },
        ActionStatus: { field: "ActionStatus", defaultValue: 0, editable:"inline" }
  
      }
    }
  }
  });
  var onDataBound = function() {
  $('td').each(function(){if($(this).text()=='Closed')
  {$(this).addClass('red')}});
  $('td').each(function(){if($(this).text()=='Open')   
  {$(this).addClass('green')}});
  
  };
  var grid = $("#Skpi1div").kendoGrid({
  dataSource: dataSource,
  dataBound: onDataBound,
  filterable: true,
  scrollable: false,
  toolbar: ["create"],
  autoBind: false, // disable autobinding as we should wait for the categories to be loaded
  columns: [
      { field:"ActionID",title:"ID", width: "65px" },
      { field:"DateCreated", title:"Date", format:"{0:yyyy-MM-dd}", editor: dateCreatedEditor, template: "#=getDateCreated(DateCreated)#", type:"date", width: "100px"},
  
      { 
      field: "SufferID", width: "120px",
      editor: sufferDropDownEditor,
      title: "Created By",
      template: "#=getSufferName(SufferID)#"
    },
    { field:"Problem",title:"Problem / Cause" },
       { 
      field: "SolverID", width: "140px",
      editor: solverDropDownEditor,
      title: "Solved By",
      template: "#=getSolverName(SolverID)#"
    },   
  
   { field:"DateSolved", title:"Date Solved", format:"{0:yyyy-MM-dd}", editor: dateSolvedEditor, template: "#=getDateSolved(DateSolved)#", type:"date", width: "90px"},
    { 
      field: "ActionStatus", width: "90px",
      editor: actionDropDownEditor,
      title: "Status",
      template: "#=getActionName(ActionStatus)#",
      attributes: {
          "class": "actions"
      }
    },
  
       { command: [{text:"Delete record",name:"destroy"}], title: " ", width: "200px" }
    ],
  editable: true ,
  }).data("kendoGrid");
  
  $.getJSON("actionsDEPARTMENT.php", function(data) {
    suffers = data;
    dataSource.fetch();
  });
  $.getJSON("actionsDEPARTMENTsolvers.php", function(data) {
    solvers = data;
    dataSource.fetch();
  });
  $.getJSON("actionsEX.php", function(data) {
    actions = data;
    dataSource.fetch();
  });
  });
  
  function sufferDropDownEditor(container, options) {
  $('&lt;input data-bind="value:' + options.field + '"/&gt;')
  .appendTo(container)
  .kendoDropDownList({      
    dataTextField: "SufferName", 
    dataValueField: "SufferID",
    dataSource: suffers,
    change: function(e) {
      //  this.css ("background-color", "blue");
   //  var value = this.value();
  //  alert (value);
  // Use the value of the widget
  } 
  });
  }
  
  
  function getSufferName(SufferID) {
  //alert ("suffer:" + SufferID);
    for (var idx = 0, length = suffers.length; idx &lt; length; idx++) {
    if (suffers[idx].SufferID == SufferID) {
  
      return suffers[idx].SufferName;
    }
  }
  }
  
  function solverDropDownEditor(container, options) {
  $('&lt;input data-bind="value:' + options.field + '"/&gt;')
  .appendTo(container)
  .kendoDropDownList({      
    dataTextField: "SolverName", 
    dataValueField: "SolverID",
    dataSource: solvers,
    change: function(e) {
      //  this.css ("background-color", "blue");
   //  var value = this.value();
  //  alert (value);
  // Use the value of the widget
  } 
  });
  }
  
  
  function getSolverName(SolverID) {
  //alert (SolverID);
  for (var idx = 0, length = solvers.length; idx &lt; length; idx++) {
    if (solvers[idx].SolverID == SolverID) {
  
      return solvers[idx].SolverName;
    }
  }
  }
  function actionDropDownEditor(container, options) {
  $('&lt;input data-bind="value:' + options.field + '"/&gt;')
  .appendTo(container)
  .kendoDropDownList({      
    dataTextField: "ActionName",
    dataValueField: "ActionStatus",
    dataSource: actions,
    change: function(e) {
   $('td').each(function(){if($(this).text()=='Closed')      
  {$(this).addClass('red')}});
      $('td').each(function(){if($(this).text()=='Open')    
  {$(this).addClass('green')}});
  } 
  });
  }
  
  function getActionName(ActionStatus) {
  for (var idx = 0, length = actions.length; idx &lt; length; idx++) {
    if (actions[idx].ActionStatus == ActionStatus) {
  
      return actions[idx].ActionName;
    }
  }
  }
  
  function getDateCreated(DateCreated) {
  var dateCreated = kendo.toString(DateCreated, "yyyy/MM/dd");
  //alert (dateCreated);
    return  dateCreated;
  }
  
  function getDateSolved(DateSolved) {
  var dateSolved = kendo.toString(DateSolved, "yyyy/MM/dd");
  //alert (dateCreated);
  return  dateSolved;
  }
  
  function dateSolvedEditor(container, options) {
  $('&lt;input data-text-field="' + options.field + '" data-value-field="' +  options.field + '" data-bind="value:' + options.field + '" data-format="' + options.format + '"/&gt;')
          .appendTo(container)
          .kendoDatePicker({});
  }
  function dateCreatedEditor(container, options) {
  $('&lt;input data-text-field="' + options.field + '" data-value-field="' + options.field + '" data-bind="value:' + options.field + '" data-format="' + options.format + '"/&gt;')
          .appendTo(container)
          .kendoDatePicker({});
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>The code for create and delete php files are the following:</p>
  
  <pre><code>//CREATE.php
  &lt;?php
  header("Content-type: application/json");
  $con = mysql_connect("localhost", "root", "");
  if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  } else {
  mysql_select_db("mapdata", $con);
  if (strlen ($_POST['models'][0]['DateCreated'])&gt; 12 )
  {   
   list($diaChar, $mes, $dia, $year) = explode(' ', $_POST['models'][0]['DateCreated']);
   $fecha = DateTime::createFromFormat('j-M-Y', $dia . "-" . $mes . "-" . $year);
   $dateCreated =  $fecha-&gt;format('Y-m-d');
  }
  else
  {
       $dateCreated = $_POST['models'][0]['DateCreated'];
  }
  echo $dateCreated;
  
  if (strlen ($_POST['models'][0]['DateSolved'])&gt; 12 )
  {   
   list($diaCharS, $mesS, $diaS, $yearS) = explode(' ', $_POST['models'][0]['DateSolved']);
   $fechaS = DateTime::createFromFormat('j-M-Y', $diaS . "-" . $mesS . "-" . $yearS);
   $dateSolved =  $fechaS-&gt;format('Y-m-d');
  }
  else
  {
       $dateSolved = $_POST['models'][0]['DateSolved'];
  }
  
   echo ($dateSolved);
  $modalidad = mysql_query ("SELECT MAX(`ActionID`) FROM actionsc", $con);
  $idCurrent = (mysql_result ($modalidad, 0));
  $idCurrent = $idCurrent + 1;
  echo $idCurrent;
  
  $rs = mysql_query("INSERT INTO actionsc (ActionID, DateCreated, SufferID, Problem, SolverID, DateSolved, ActionStatus) VALUES('". mysql_real_escape_string($idCurrent, $con) . "','". mysql_real_escape_string($dateCreated, $con) . "', '" . mysql_real_escape_string($_POST['models'][0]['SufferID'], $con) . "', '" . mysql_real_escape_string($_POST['models'][0]['Problem'], $con) . "', '" . mysql_real_escape_string($_POST['models'][0]['SolverID'], $con) . "', '" . mysql_real_escape_string($dateSolved, $con) . "', '" .     mysql_real_escape_string($_POST['models'][0]['ActionStatus'], $con) . "')");
  
  
  if ($rs) {
  echo json_encode($rs);
  $res = mysql_query("SELECT * From actionsc WHERE `ActionID`='$idCurrent'");
  
  $arr = array();
  while($obj = mysql_fetch_array($res))
  {
    $arr[] = array(
       'ActionID' =&gt; $obj["ActionID"],
      'DateCreated' =&gt; $obj["DateCreated"],
       'SufferID' =&gt; str_replace("\'", "'", $obj["SufferID"]),
       'Problem' =&gt; str_replace("\'", "'", $obj["Problem"]),
       'SolverID' =&gt; str_replace("\'", "'", $obj["SolverID"]),
       'DateSolved' =&gt; str_replace("\'", "'", $obj["DateSolved"]),
       'ActionStatus' =&gt; str_replace("\'", "'", $obj["ActionStatus"]),
    ); 
  echo json_encode($arr);
  
  }
  }
  else {
      header("HTTP/1.1 500 Internal Server Error");
       echo "Failed on insert:";
  }
  mysql_close($con);
  }
  ?&gt; 
  
  //DESTROY
  &lt;?php
  header("Content-type: application/json");
  $con = mysql_connect("localhost", "root", "");
  if (!$con)
  {
    die('Could not connect: ' . mysql_error());
  } else {
     mysql_select_db("mapdata", $con);
     echo ( $_POST['models'][0]['ActionID']);
     $rs = mysql_query("DELETE FROM actionsc WHERE ActionID = " . $_POST['models'][0]['ActionID']);
     if ($rs) {
      echo json_encode($rs);
    }
    else {
          header("HTTP/1.1 500 Internal Server Error");
          echo "Failed on delete: " . $_POST['models'][0]['ActionID'];
    }
     mysql_close($con);
  }
  ?&gt; 
  </code></pre>
  
  <p>Problems appear when I try to add a new record and when I try to delete an existing one:</p>
  
  <ul>
  <li>When CREATE, the network command GET for createC.php appears twice, and two records are added to dataSource. I have been reading during days in forums about how to solve this issue.</li>
  </ul>
  
  <p>I have tried with two things: 
  1) When create is complete, I have tried to read and refresh my dataSource
  2) Return manually in json the record recently added.</p>
  
  <p>Conclusion: problem still appears.</p>
  
  <ul>
  <li>When DESTROY, the ID (ActionID) of the record posted is always the same. No idea about this.</li>
  </ul>
  
  <p>I have spent my last four days in this, sorry for my code. 
  Thank you so much for your support, really thank you.</p>
  
  <p>Regards, Manu.</p>