2012-12-05 32 views
1

是否可以重新加載一行ATK4 Grid?是否有可能重新加載一行ATK4網格?

例如,在Form中進行更改後,大多數時間在CRUD中只需重新加載一個網格行而不是所有Grid對象。

編輯:

我不說明確表示,我很感興趣,此功能專爲ATK4(敏捷工具包)框架抱歉。我在這個問題中增加了atk4標籤,但沒有在主題和問題主體中提到「ATK4」。對不起。

我或多或少知道如何以標準方式使用jQuery來做到這一點,但我感興趣也許有一些方法如何在ATK4框架中更輕鬆地做到這一點。像$ grid-> row(ID) - > reload()或類似的東西。

+0

簡單的ajax調用解決了這個問題。 – Stranger

+1

如果您正在使用將數據發送到服務器以進行保存的AJAX調用來執行這些更改,則可以使用它的onSuccess部分來查找具體行並使用提交表單中的值更新其內容。 – shadyyx

回答

1

在帶有js() - > univ() - > reloadRow($ id)的atk4中,它處理jQuery客戶端部件以刷新一行。現在,當reload_row請求到達時,網格(服務器部分)也需要輸出一行而不是整個網格。這可以通過以下電網延伸來完成(基於如何網格/在線運行正常):

Class TestGrid extends Grid { 

    function init() { 
    parent::init(); 
    if($row_id=$_GET[$this->name.'_reload_row']){ 
     $g=$this; 
     $this->api->addHook('pre-render',function() use($g,$row_id){ 
     $g->precacheTemplate(); 
     foreach($g->getIterator() as $g->current_id=>$g->current_row){ 
      if($row_id == $g->current_id) { 
      $g->formatRow(); 
      $result=$g->rowRender($g->row_t); 
      if($g->api->jquery)$g->api->jquery->getJS($g); 
      break; 
      } 
     } 
     throw new \Exception_StopRender($result); 
     }); 
    } 
    } 
} 

爲了與頁面上的CRUD測試這個(也應該與電網只工作):

$g=$this->add('CRUD', array('grid_class' => 'TestGrid')); 
$g->setModel('User'); 
if($g->grid) { 
    $g->grid->addColumn('button', 'rerow'); 
    if($row_id = $_GET['rerow']){ 
    $g->grid->js()->univ()->reloadRow($row_id)->execute(); 
    } 
} 

這會產生一個帶額外按鈕'Rerow'的CRUD,它將在單擊時重新加載特定行。

0

當談到CRUD時,可能你有一些包含數據行的概述。 在具體行上點擊Edit後我會打開一個彈出窗口,其中包含一個允許用戶更改該行數據的窗體。正如你所要求的只是刷新一個具體的行,我也猜你正在使用AJAX調用發送和存儲數據。

那麼,在這裏你可以使用AJAX的onSuccess部分的優勢(當使用jQuery $.ajax時)。數據提交後,您必須存儲行ID以正確解決問題。在成功執行AJAX調用之後,將調用onSuccess句柄,您應該在其中實現將使用先前存儲的行ID對行進行編址的代碼,並使用當前已提交和存儲的單元格重置單元格中的數據。

1

敏捷工具包不提供此功能的開箱即用功能。它曾經是ui.atk4_grid.js的一部分,它仍然可以找到,它會發送一個自定義的請求到網格視圖,但是這些表並不總是和這個一起玩,然後有時你還需要重新加載多行。

你有所有的工具來爲此構建附加組件。您需要調用一次grid :: formatRow()並返回HTML,然後使用JS插入到網格中。

下面是老(刪除)方法:

function getRowContent($id,$datatype='jquery'){ 

    // if DB source set 
    if(isset($this->dq)){ 
     // *** Getting required record from DB *** 
     $idfield=$this->dq->args['fields'][0]; 
     if($idfield=='*'||strpos($idfield,',')!==false)$idfield='id'; 
     $this->dq->where($idfield,$id); 
     //we should switch off the limit or we won't get any value 
     $this->dq->limit(1); 
     #zak: This fix is if grid is not using the $this->api->db database but some else it hsould be depending only on $this->> 
     $row_data=$this->dq->do_getHash(); //$this->api->db->getHash($this->dq->select()); 
    } 
    // if static source set 
    elseif(isset($this->data)){ 
     $found=false; 
     foreach($this->data as $index=>$row){ 
      if($row['id']==$id){ 
       $row_data=$row; 
       $found=true; 
       break; 
      } 
     } 
     // no data found, returning empty string 
     if(!$found)return ""; 
    } 
    else return ""; 
    // *** Initializing template *** 
    $this->precacheTemplate(false); 

    // *** Rendering row *** 
    $this->current_row=$row_data; 
    $this->formatRow(); 

    // *** Combining result string *** 
    $func='formatRowContent_'.$datatype; 
    return $this->$func($id); 
} 
protected function formatRowContent_html($id){ 
    $this->row_t->set($this->current_row); 
    return $this->rowRender($this->current_row); 
} 
protected function formatRowContent_ajax($id){ 
    $result=""; 
    foreach($this->columns as $name=>$column){ 
     $result.=$this->current_row[$name]."<t>".$this->current_row[$name.'_original']. 
      // appending styles as structured string 
      "<t>".$this->getFieldStyle($name,$id). 
      "<row_end>"; 
    } 
    return $result; 
} 
protected function formatRowContent_jquery($id){ 
    $result=array(); 
    $i=1; 
    foreach($this->columns as $name=>$column){ 
     $result[$i]['data']=array('actual'=>$this->current_row[$name], 
      'original'=>$this->current_row[$name.'_original']); 
     $result[$i]['params']=$this->tdparam[$this->getCurrentIndex()][$name]; 
     $i++; 
    } 
    $result=json_encode($result); 
    return $result; 
} 

希望這會幫助你。

相關問題