如何动态更新角度ui-grid列的columnDef [英] How to update the columnDef of an angular ui-grid column dynamically

查看:223
本文介绍了如何动态更新角度ui-grid列的columnDef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我面临的问题是我想更新columnDef定义的field属性,以根据传递给指令的某些配置显示不同的值.我在这个笨蛋中有一个笨拙的版本:

So the issue I'm facing is I would like to update the field property of a columnDef definition to show a different value based on some configuration that's being passed into the directive. I have a dumbed down version in this plunk:

http://plnkr.co/edit/gmjUcQsnIOpqWwkoYiI8?p=preview

单击该插件中的按钮应将电子邮件从actual切换到pretend.它在作用域上的columnDefs上循环,然后将字段从email.actual更改为email.pretend.更改columnDefs之后是否需要某种刷新"功能?我尝试了gridApi.core.refresh(),但没有执行任何操作.感谢您的输入!

Clicking the button in that plunk should switch the emails from actual to pretend. It's looping over the columnDefs on scope and then altering the field to be email.pretend from email.actual. Do I need some kind of "refresh" function after changing the columnDefs? I tried gridApi.core.refresh() but that did not do anything. Thanks for any input!

推荐答案

http://plnkr. co/edit/ujIpJFFGRAwNUKiy0Bnm?p = preview

$scope.otherColumn = {displayName: 'Pretend', field: 'email.pretend'};
//change the field - is this possible???
$scope.changeField = function changeField() {
    $scope.otherColumn = $scope.columnDefs.splice(1, 1, $scope.otherColumn)[0];
}

您只需在columnDefs数组中添加/删除该项目即可.

You just add / remove the item from the columnDefs array and it will do it.

这篇关于如何动态更新角度ui-grid列的columnDef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆