如何动态编辑" noRowsToShow"文本?

时间:2017-09-26 11:49:47

标签: angular ag-grid

相关:How To translate "No Rows To Show" message in ag-grid?

解决方案的问题在于它只能工作一次。网格可见后,更改" noRowsToShow"是不可能的。在我要搜索解决方案之前,我会在语言更改后替换整个网格,我正在寻找另一个。

我目前所做的是在每次语言更改后,我将旧的localeText替换为新的transaleText。这显然没有用。它看起来像这样:

this.gridOptions.localeText = {
    noRowsToShow: this.translate("noRows", "DE");
};

事实上它确实有效,但gridOptions并没有被新的替换。

是否有另一种方法可以用新的翻译替换localeText?

编辑:我在Github上发现了问题同样的问题,但没有回答:https://github.com/ag-grid/ag-grid/issues/1286

我希望他能回答我的问题

1 个答案:

答案 0 :(得分:0)

如果您使用localeText,请查看文档,您只需提供(单个)语言即可使用。如果你想使用外部翻译,那么它说要使用localeTextFunc

var gridOptions = {

// standard grid settings, thrown in here to pad out the example
enableSorting: true,
enableFilter: true,
enableColResize: true,
columnDefs: columnDefs,

localeTextFunc: function(key, defaultValue) {

    // to avoid key clash with external keys, we add 'grid' to the start of each key.
    var gridKey = 'grid.' + key;

    // look the value up. here we use the AngularJS 1.x $filter service, however you can use whatever
    // service you want, AngularJS 1.x or otherwise.
    var value = $filter('translate')(gridKey);
    return value === gridKey ? defaultValue : value;
}

};

相关问题