2013-07-01 39 views
0

我有一張可讀表格: 日期格式的可安排問題

 
       $("#old_tab_handsontable").handsontable({ 
        data: data, 
        startRows: 1, 
        colHeaders: ['ID', 'datePers', 'dateArchive', 'dateAncienne', 'dateDef', 'IS'], 
        columns: [ 
         {data: 'ID'}, 
         {data: 'datePers', type: 'date'}, 
         {data: 'dateArchive', type: 'date'}, 
         {data: 'dateHist.old', type: 'date'}, 
         {data: 'dateDef', type: 'date'}, 
         {data: 'IS'} 
        ], 
        colWidths: [100, 100, 100, 100, 100, 100] 
       }); 
所有通道都是用我的數據庫完成的。我有一個按鈕,節省了車道的變化:
 
     $("#save").click(function() { 
      var handsontable = $("#old_tab_handsontable").data('handsontable'); 
      console.log(handsontable.getData()); 
      $.ajax({ 
       url: "/Reporting/saveperspective", 
       data: {'data': handsontable.getData()}, 
       type: 'POST', 
       success: function() { 
        generateJsMessage("Les perspectives ont bien été modifiées", 'success'); 
       }, 
       error: function() { 
        generateJsMessage("Une erreur s'est produite", 'error'); 
       } 
      }); 
     }); 

我的問題是,如果我一個日期保存爲2012-02-01,當我將刷新頁面,所考慮的電池會顯示2012-01- 02。當我console.log(handsontable.getData());它仍然是2012-02-01,當我var_dump($ _ POST ['data']),它仍然是2012-02-01 ... 我的數據庫(我不允許觸摸/修改/ ...)是在SQL Server上。

我的更新控制器是:

 
     public function saveperspectiveAction() { 
      $this->_helper->getHelper('layout')->disableLayout(); 
      $this->_helper->viewRenderer->setNoRender(); 
      $data = $_POST['data']; 
      _dump($_POST['data']); 
      foreach ($data as $one): 
       $this->reporting->updateListPerspectives($one['ID'], $one['datePers'], $one['dateArchive'], $one['dateDef'], $one['IS']); 
      endforeach; 
      return true; 
     } 

和我消氣控制器

 
    public function getperspectiveAction() { 
      $resultSql = $this->reporting->getListPerspectives(); 
      $this->_helper->getHelper('layout')->disableLayout(); 
      $this->_helper->viewRenderer->setNoRender(); 
      $tab = array(); 
      foreach ($resultSql as $oneline) { 
       if ($oneline['dateHist.old'] == NULL) {

array_push($tab, array('ID' => $oneline['theDate_id'], 'datePers' => $oneline['datePers']->format('Y-m-d'), 'dateArchive' => $oneline['dateArchive']->format('Y-m-d'), 'dateHist.old' => " ", 'dateDef' => $oneline['dateDef']->format('Y-m-d'), 'IS' => $oneline['isCriteria'])); } else { array_push($tab, array('ID' => $oneline['theDate_id'], 'datePers' => $oneline['datePers']->format('Y-m-d'), 'dateArchive' => $oneline['dateArchive']->format('Y-m-d'), 'dateHist.old' => $oneline['dateHist.old']->format('Y-m-d'), 'dateDef' => $oneline['dateDef']->format('Y-m-d'), 'IS' => $oneline['isCriteria'])); } } print json_encode($tab); } </pre>
+0

您需要定義'dateFormat'財產。 – 2013-07-01 17:21:38

回答

1

嘗試設置日期格式:

  $("#old_tab_handsontable").handsontable({ 
       data: data, 
       startRows: 1, 
       colHeaders: ['ID', 'datePers', 'dateArchive', 'dateAncienne', 'dateDef', 'IS'], 
       columns: [ 
        {data: 'ID'}, 
        {data: 'datePers', type: 'date', dateFormat: 'mm/dd/yy'}, 
        {data: 'dateArchive', type: 'date', dateFormat: 'mm/dd/yy'}, 
        {data: 'dateHist.old', type: 'date', dateFormat: 'mm/dd/yy'}, 
        {data: 'dateDef', type: 'date', dateFormat: 'mm/dd/yy'}, 
        {data: 'IS'} 
       ], 
       colWidths: [100, 100, 100, 100, 100, 100] 
      }); 
+0

是的,它有幫助,謝謝! – Valinor