2012-09-04 22 views
0

我正在使用Agile Toolkit进行某些开发,并希望扩展现有的网格控件,以便每行都包含数据(就像现在这样),而且还链接到页面使用包含该ID的查询字符串。我希望能够做一些事情,如:将网格UI元素扩展为链接到页面

$this->add('Grid', 'short-name', 'template-tag', array('page?id=', 'id'))->setModel('mydatasource'); 

我目前可以使用以下方法:

$this->add('Grid', 'short-name', 'template-tag')->setModel('mydatasource'); 

但我想可以指定我链接到一个格式的页面与外地我想通过让点击任意位置在第二排:

1  Jack Johnson  Clerk 
2  John Doe   Executive 

带我到:myapp.com/page?id=2

我将如何去扩展Grid元素来做到这一点?还是需要从AbstractView或Lister中一直延伸下去?

谢谢!

全工作溶液:

precacheTemplate除去从row_t用于我的HTML模板中定义的变量的参照。所以我遵循现有的做法,添加了另一个重置的变量(即它设置为to的地方)为 - 这样它就留在内存中作为参考返回到通用formatRow中的模板字段,它正在从Basic重载格。

罗马之前曾提到过这一些,但我终于得到了失去的链接,我不得不重置。

最好的理解方法是逐行比较我的网格和基本网格(是的,我知道我从高级延伸)。

希望可以帮助其他人有完全相同的问题。

在页面

$this->add('ExtendedUI_GridLinkedRow', array('dest_page'=>'home', 'name'=>'assessments'), 'assessments') 
    ->setModel('GrantAssessment') 
    ->addCondition('uid', 1); 

GridLinkedRow.php

<?php 

class ExtendedUI_GridLinkedRow extends Grid_Advanced { 

    function init(){ 
     parent::init(); 
    } 

    function defaultTemplate(){ 
     return array('ExtendedUI/grid_linked_row'); 
    } 

    function precacheTemplate(){ 
     // pre-cache our template for row 
     // $full=false used for certain row init 
     $row = $this->row_t; 
     $col = $row->cloneRegion('col'); 

     // tbody -> column 
     $row->setHTML('row_id','<?$id?>'); 
     $row->trySetHTML('odd_even','<?$odd_even?>'); 
     $col->setHTML('dest_link','<?$page_link?>'); 
     $row->del('cols'); 

     // thead -> column 
     $header = $this->template->cloneRegion('header'); 
     $header_col = $header->cloneRegion('col'); 
     $header_sort = $header_col->cloneRegion('sort'); 

     // Totals -> column 
     if($t_row = $this->totals_t){ 
      $t_col = $t_row->cloneRegion('col'); 
      $t_row->del('cols'); 
     } 

     $header->del('cols'); 

     foreach($this->columns as $name=>$column){ 
      $col->del('content'); 
      $col->setHTML('content','<?$'.$name.'?>'); 

      if(isset($t_row)){ 
       $t_col->del('content'); 
       $t_col->setHTML('content','<?$'.$name.'?>'); 
       $t_col->trySetHTML('tdparam','<?tdparam_'.$name.'?>style="white-space: nowrap"<?/?>'); 
       $t_row->appendHTML('cols',$t_col->render()); 
      } 

      // some types needs control over the td 

      $col->setHTML('tdparam','<?tdparam_'.$name.'?>style="white-space: nowrap"<?/?>'); 

      $row->appendHTML('cols',$col->render()); 

      $header_col->set('descr',$column['descr']); 
      $header_col->trySet('type',$column['type']); 

      // TODO: rewrite this (and move into Advanced) 
      if(isset($column['sortable'])){ 
       $s=$column['sortable']; 
       // calculate sortlink 
       $l = $this->api->getDestinationURL(null,array($this->name.'_sort'=>$s[1])); 

       $header_sort->trySet('order',$column['sortable'][0]); 
       $header_sort->trySet('sorticon',$this->sort_icons[$column['sortable'][0]]); 
       $header_sort->set('sortlink',$l); 
       $header_col->setHTML('sort',$header_sort->render()); 
      }else{ 
       $header_col->del('sort'); 
       $header_col->tryDel('sort_del'); 
      } 

      if($column['thparam']){ 
       $header_col->trySetHTML('thparam',$column['thparam']); 
      }else{ 
       $header_col->tryDel('thparam'); 
      } 

      $header->appendHTML('cols',$header_col->render()); 

     } 
     $this->row_t = $this->api->add('SMlite'); 
     $this->row_t->loadTemplateFromString($row->render()); 

     if(isset($t_row)){ 
      $this->totals_t = $this->api->add('SMlite'); 
      $this->totals_t->loadTemplateFromString($t_row->render()); 
     } 

     $this->template->setHTML('header',$header->render()); 
    } 

    function formatRow(){ 

     if(!$this->columns)throw $this->exception('No columns defined for grid'); 

     foreach($this->columns as $tmp=>$column){ 
      $this->current_row[$tmp.'_original'][email protected]$this->current_row[$tmp]; 

      $formatters = explode(',',$column['type']); 
      foreach($formatters as $formatter){ 
       if(!$formatter)continue; 
       if(method_exists($this,$m="format_".$formatter)){ 
        $this->$m($tmp,$column); 
       }else throw new BaseException("Grid does not know how to format type: ".$formatter); 
      } 
      // setting cell parameters (tdparam) 
      $this->applyTDParams($tmp); 
      if($this->current_row[$tmp]=='')$this->current_row[$tmp]=' '; 
     } 
     $this->row_t->setHTML('page_link', $this->api->url($this->dest_page, array('id'=>$this->current_id))); 
     return $this->current_row; 
    } 

} 

对于模板:

grid_linked_row.html

<?$Misc?> 
<div id="<?$_name?>" class="atk-grid"> 
    <div class="atk-grid-panel"> 
    <?quick_search?><?/?> 
    <div class="atk-buttons"><?grid_buttons?><?/?></div> 
    </div> 
    <table width="<?table_width?>100%<?/?>"> 
    <?header?> 
    <thead class="ui-widget-header"><tr> 
     <?cols?> 
     <?col?> 
     <th class="ui-widget-header" nowrap <?$thparam?>><?sort?><i style="float: left" class="ui-icon <?$sorticon?>"></i><a href="<?$sortlink?>"><?/sort?><?descr?>Customer<?/?><?sort_del?></a><?/?></th> 
     <?/col?> 
     <?/cols?> 
    </tr></thead> 
    <?/header?> 

    <tbody class="grid_body"> 
     <?rows?> 
     <?row?> 
     <tr class="<?$odd_even?>" data-id="<?$row_id?>" rel="<?$row_id?>"> 
     <?cols?> 
     <?col?> 
     <td <?$tdparam?>><a href="<?$dest_link?>"><?$content?></a></td> 
     <?/col?> 
     <?/cols?> 
     </tr> 
     <?/row?> 

     <?totals?> 
     <tr class="atk-grid-totals"> 
     <?cols?> 
     <?col?> 
     <td <?$tdparam?>><?$content?></td> 
     <?/col?> 
     <?/cols?> 
     </tr> 
     <?/totals?> 
     <?/rows?> 


    </tbody> 
    <?full_table?> 
    <?/full_table?> 
    </table> 
    <?not_found?><div class="atk-grid-notfound ui-state-highlight ui-corner-all"><i class="ui-icon ui-icon-alert float-left"></i>No Records Found</div><?/not_found?> 
    <div class="atk-paginator"><?paginator?><?/?></div> 
    <?hidden_forms?><?/hidden_forms?> 
</div> 

回答

0

如果你想换一个链接内网格的所有文本值,可以使用以下命令:

$this->add('MyGrid',array('dest_page'=>'page'), 'template-tag'); 


class MyGrid extends Grid { 
    function format_text($field){ 
     parent::format_text($field); 

     // Wrap the value inside a link 
     $this->current_row_html[$field]='<a href="'. 
      $this->api->url($this->dest_page, array('id'=>$this->current_id).'">'. 
      ($this->current_row_html[$field]?: 
      htmlspecialchars($this->current_row[$field],ENT_NOQUOTES,'UTF-8')). 
      '</a>' 
    } 
} 
+0

喜@romaninsh id字段来了空白同时在precachetemplate和init –

+1

试试'this-> current_id',如果你在formatRow或format_XXX里面 – romaninsh

+0

试过@romaninsh $ this-> setHTML('dest_link',$ this-> api-> url($ this-> dest_page,array('id'= > $这 - > current_id))); 里面formatRow但没有骰子 - 它有url(和id字段),但我不知道模板对象是什么,我需要使用。即$ this-> template-> setHTML .....或$ this-> setHTML .... –

相关问题