2015-10-19 38 views
0

我有我定义columnDefs的config.json文件。我想将超链接文本添加到名称字段并将其重定向到包含该行信息的页面。我试着与SO一些例子,但没有成功..添加超链接文本到特定的行ui-grid

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 ==“东西”

回答

0

当你点击一个名字,它需要你下一个页面

$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网

 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; 
     } 
    }; 

它得到一排,当我们选择一个记录

0123所选的行
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); 
};