【问题标题】:add hyperlink text to specific rows ui-grid将超链接文本添加到特定行 ui-grid
【发布时间】:2016-01-17 21:03:00
【问题描述】:

我有定义 columnDefs 的 config.json 文件。我想将超链接文本添加到名称字段并重定向到包含该行信息的页面。我尝试了一些关于 SO 的示例,但没有成功..

config.json

    "columnDefs":[
      {
        "name": "name"
      },
      {
        "name": "object_type_s"
      }
   ........
    ]

控制器

$scope.gridOptions = {
  columndDefs: config.columnDefs,
  ......

}

如果我像这样将 cellTemplate 放在配置文件中

{
"name": "name",
 "cellTemplate": "<a href="#">"
},

这将在我的网格中的所有行中添加超链接。例如,我想仅将超链接添加到

的行

$scope.gridOptions.data.object_type == "SOMETHING"

【问题讨论】:

    标签: javascript html angularjs angular-ui-grid


    【解决方案1】:

    当你点击一个名字时,它会带你进入下一页

     $scope.gridOptions = {
                paginationPageSizes : [ 25, 50, 75 ],
                paginationPageSize : 25,
                enableColumnResizing : true,
                enableSorting : true,
                enableRowSelection : true,
                enableSelectAll : true,
                enableRowHeaderSelection: true,
                selectionRowHeaderWidth : 35,
                rowHeight : 35,
            showGridFooter : true,
    

    行模板用于获取 ui-grid 上的选定行

            rowTemplate : rowTemplate(),
    
            columnDefs : [
            {
            field : 'id',
            name : 'id',
            width: 200,
            },
            {   
    
                field : 'name',
                name  : 'name',
                width : 120,
                sort  : {
                    priority : 0,
                },
                cellTemplate:'<div >' + '<a href="test.html">'+ '</a>' + '</div>',
            }
            } ],
              onRegisterApi: function(gridApi){
                  $scope.gridApi = gridApi;
            }
        };
    

    当我们选择一条记录时,它得到一行

    function rowTemplate() {
        return '<div ng-click="grid.appScope.rowDblClick(row);">' + ' <div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell"  ui-grid-cell></div>' + '</div>';
    }
    

    当你点击一行时,你使用这个方法得到一行

    $scope.rowDblClick = function(row) {
        console.log('The selected object id is : ', row.entity.id);
        console.log('The selected object nameis : ', row.entity.name);
    };
    

    【讨论】:

      猜你喜欢
      • 2023-01-11
      • 1970-01-01
      • 2011-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-22
      相关资源
      最近更新 更多