如何在Ag-Grid过滤器中使用AngularJS 1



我想在AngularJS中为Ag-Grid 5.2.0创建一个过滤器。下面是我的代码:

    var columnDefs = [
        {headerName: "Test1", field: "test1", filter: MyCustomFilter},
        {headerName: "Test2", field: "test2"},
    ];         
    vm.gridOptions = {
        enableServerSideSorting: true,
        enableServerSideFilter: true,
        columnDefs: columnDefs,
        datasource: getDataSource(),
        paginationPageSize: 10,
        rowModelType: 'pagination'
    };
    // Class function.
    function MyCustomFilter() {}
    // mandatory methods
    MyCustomFilter.prototype.init = function (params) {};
    MyCustomFilter.prototype.getGui = function () {return "<div>{{ 'testkey' | translate}}</div>"};
    MyCustomFilter.prototype.isFilterActive = function() {return true;};
    MyCustomFilter.prototype.doesFilterPass = function (params) { return true;};
    MyCustomFilter.prototype.getApi = function () {};

问题是AngularJS不计算翻译过滤器。如何将AngularJS元素添加到Ag-Grid过滤器中?

我已经找到解决办法了:

function getGui() {
    var filterScope = $rootScope.$new(true);
    var filter = $compile("<div>{{ 'testkey' | translate}}</div>")(filterScope);
    filterScope.$digest();
    return filter[0];
};

最新更新