angular-ui-grid:将值作为自定义模板中的参数传递?

时间:2016-08-04 07:08:48

标签: angularjs angular-ui-grid

我生成了一个包含所有服务器端分页和排序的网格。我还在网格中插入了编辑选项列。这个,我可以使用自定义节制功能。但是我一直在努力将“id”作为编辑参数传递。

columnDefs: [
          { name: "Options2", displayName: 'Select', cellTemplate: '<div ng-click="alert();">click me</div>' },
          { name: 'ContactID', displayName: 'ID', },
          { name: 'FirstName' },
          { name: 'LastName' },
          {
              name: 'Options',
              cellTemplate: '<div>' +
                        '  <a ui-sref="editcontact({contactId: ContactID})">Edit</a>' +
                        '</div>'
          }

        ],

将鼠标悬停在编辑选项上: enter image description here

另外,路由:

.state('editcontact',
     {
         url: '/editcontact/:contactId',
         controller: 'EditContactCtrl',
         templateUrl: 'views/contact/editContact.html', controllerAs: 'vm',
         resolve: {
             contactInfo: ['contactService', '$stateParams', function (contactService, $stateParams) {
                 return contactService.getContact($stateParams.contactId).then(function (response) {
                     return response;
                 });
             }]
         },

     })

2 个答案:

答案 0 :(得分:1)

好的,所以我通过访问模板中的范围来确定

编辑/删除模板:

%h_text=text(matrix_val(size(matrix_val,1),1),matrix_val(size(matrix_val,1),k+1),20,param_values{k},'FontSize',[myfontsize]); % plot text
%**********firstly ,remove '\'from param_values{k}, like 0.1\mA to 0.1mA
param_v_temp= param_values{k};
para_index=strfind(param_v_temp,'\');
param_v_temp(para_index)=[];

%h_text=text(matrix_val(size(matrix_val,1),1),matrix_val(size(matrix_val,1),k+1),20,param_v_temp,'FontSize',[myfontsize]); % plot text 'FontSize',
h_text=text(matrix_val(size(matrix_val,1),1),matrix_val(size(matrix_val,1),k+1),20,param_v_temp,'FontSize',[myfontsize]); % plot text 'FontSize',
set(h_text,'HorizontalAlignment','left');
ws = get(h_text,'Extent')*[0;0;1;0];
set(h_text,'DeleteFcn','DelStr','ButtonDownFcn',sprintf('MoveStr(%1.15g)',ws),'FontName','Arial');
%set( h_text,'DeleteFcn','DelStr','ButtonDownFcn',sprintf('MoveStr(%1.15g)',ws),'FontSize',[10],'FontName','Helvetica');
h_extent = get(h_text,'Extent');
p = patch(h_extent*[1 1 1 1; 0 0 0 0; 1 1 0 0; 1 1 1 1],...
    h_extent*[0 0 0 0; 1 1 1 1; 0 0 0 0; 0 1 1 0],[1 1 1 1]*1e-6,[0.95 0.95 0.95],'Linestyle','none');
set(p,'UserData', h_text,'DeleteFcn','DelPointer')
set(h_text,'UserData',p)

控制器中的删除功能:

{
              name: 'Options',
              cellTemplate: '<div class="ui-grid-cell-contents ng-binding ng-scope">'+
                  '<button class="btn btn-danger '+
                       'btn-xs " ng-click="grid.appScope.deleteRow(row)">' +
                  '<span class="glyphicon glyphicon-trash"></span></button>'
                  +
                  '<button ui-sref="editcontact({ contactId: \'{{row.entity.ContactID}}\'})" class="btn btn-warning ' +
                       'btn-xs " >' +
                  '<span class="glyphicon glyphicon-pencil"></span></button>'+
                  '</div>'
          }

答案 1 :(得分:0)

您可以尝试使用angular ui-router传递参数(检查$ stateparam)。 https://github.com/angular-ui/ui-router/wiki/URL-Routing

如果还不够,你能成为一个小问题吗?