如何动态更新角度 ui-grid 列的 columnDef [英] How to update the columnDef of an angular ui-grid column dynamically
问题描述
所以我面临的问题是我想更新 columnDef
定义的 field
属性,以根据传入的某些配置显示不同的值指令.我在这个 plunk 中有一个简化版:
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
点击那个 plunk 中的按钮应该将电子邮件从 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屋!