0

我正在使用 Agile Toolkit 进行一些开发,并希望扩展现有的网格控件,以便每一行都包含数据(就像现在一样),但也链接到带有包含 ID 的查询字符串的页面。我希望能够做类似的事情:

$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 的位置) - 这样它就留在内存中作为返回到从 Basic 重载的通用 formatRow 内的模板字段的参考网格。

Roman 之前提到过其中一些,但我终于找到了我必须重置的缺失链接。

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

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

在页面上

$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']=@$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>
4

1 回答 1

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>'
    }
}
于 2012-09-06T10:10:20.560 回答