我想在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过滤器?
答案 0 :(得分:0)
我已经找到了解决方案:
function getGui() {
var filterScope = $rootScope.$new(true);
var filter = $compile("<div>{{ 'testkey' | translate}}</div>")(filterScope);
filterScope.$digest();
return filter[0];
};