1

我有一个角度网格,第一列行必须显示为锚链接或基于该单元格值的 javascript 条件的标签,该单元格值不以字符“M”开头。如果第 1 列的单元格值以字符“M”开头,则该列应为标签,否则应为 hyeprlink。我确实相信我必须使用两个不同的单元格模板,但不确定如何在 uigrid 的行数据绑定事件中调用它们。下面是代码。

锚和标签的模板:

var linkCellTemplate = '<div class="ngCellText" ng-class="col.colIndex()">' +
               '  <a  class="text-blue-color text-underline" href="' + getURL() + '/ClaimDetail/Index?TagNumber={{row.entity.TagNumber}}&from=linkcomfort&Style=' + Style + '" target="_blank";">{{row.entity.TagNumber}}</a>' +
               '</div>';
var labelCellTemplate = '<div class="ngCellText" ng-class="col.colIndex()">' +
              '  <label>{{row.entity.TagNumber}}</label>' +
              '</div>';

下面是格子

        $scope.ComfortPlanGrid = {
        enableGridMenu: true,
        exporterMenuCsv: true,
        exporterMenuPdf: false,
        gridMenuShowHideColumns: true,
        enableRowSelection: false,
        enableColumnMenus: false,
        enableFiltering: false,
        enablePaging: false         

    };
    $scope.ComfortPlanGrid.columnDefs = config.headers.comfortPlansHeadersGrid;

下面是网格标题

   var headers = {
    comfortPlansHeadersGrid: [
        { field: 'TagNumber', width: 130, displayName: 'Claim Tag Nbr', cellTemplate: linkCellTemplate },
        { field: 'CustomerNumber', width: 200, displayName: 'Customer/Dealer' },
        { field: 'Status', width: 80, cellTooltip: true },
        { field: 'StatusDate', width: 175, displayName: 'Status Date' },
        { field: 'Description', displayName: 'Description', width: 270, cellTemplate: claimDetailTemplate },
        { field: 'ContractNumber', width: 200, displayName: 'Contract Number', headerTooltip: 'Contract Number' },
        { field: 'ServiceDate', width: 175, displayName: 'Service Date', headerTooltip: 'Service Date' }
    ]};

任何有关如何实现这一点的帮助表示赞赏。

4

1 回答 1

0

Try the below code:

Add the celltemplate in the coldef on the relevant column

cellTemplate: DisplayConditionalTemplate(value)


function DisplayConditionalTemplate(value){
var linkCellTemplate = '<div class="ngCellText" ng-class="col.colIndex()">' +'  <a  class="text-blue-color text-underline" href="' + getURL() + '/ClaimDetail/Index?TagNumber={{row.entity.TagNumber}}&from=linkcomfort&Style=' + Style + '" target="_blank";">{{row.entity.TagNumber}}</a>' +                  '</div>';
var labelCellTemplate = '<div class="ngCellText" ng-class="col.colIndex()">'+'  <label>{{row.entity.TagNumber}}</label>' +                  '</div>';

if(value.charAt(0) === 'M')
   return labelCellTemplate;
else
  return linkCellTemplate;
}
于 2016-11-05T04:17:56.920 回答