1

我有两个简单的要求

a) I need to programmatically change the number of columns displaying in igGrid
b) I need to programmatically update the filters in igGrid

我的印象是,要以编程方式更改列数,您首先需要“销毁”网格,然后重新创建它。

要更新过滤器,您只需执行此操作

grid.igGridFiltering("filter", ([{ fieldName: "Column1", expr: true, cond: "true" }]));

调用我的代码时总是出现此错误

cannot call methods on igGridUpdating prior to initialization; attempted to call method 'destroy'

这是一个代码片段

scope.changeView = function(v) {
    var grid = scope.element; //from directive 
    if (grid.data("igGrid") != null) {
        grid.igGrid('destroy');
    }
    updateGrid(grid, v);
};

function updateGrid(grid, v) {
    scope.gridOptions = coreFunctions.gridOptions(); //from service 
    scope.gridOptions.dataSource = scope.dataSource;
    var cols = JSON.parse(v.Json);
    cols = cols.fields;
    scope.gridOptions.columns = [];
    angular.forEach(cols, function(value, index) {
        scope.gridOptions.columns.push({ 'headerText': value, 'key': value, width: '200px' });
    });
    grid.igGrid(scope.gridOptions); //error occurs here! 
    grid.igGrid('dataBind');
    grid.igGridFiltering("filter", ([{ fieldName: "Column1", expr: true, cond: "true" }]));
}
4

2 回答 2

0

You are right that you will need to destroy the widget and recreate it again using the new columns. Depending on the scenario it may be less painful to use the renderMultiColumnHeader method, which takes an array of columns as an argument. So this method will re-render the grid with the columns you have passed

于 2015-02-27T07:24:44.217 回答
0

我知道这个问题很老,但我遇到了同样的问题,发现以下是 (b) 的简单解决方案:

假设您认为这是

<div id="myGrid"></div>

这在一个脚本中

$('#myGrid').igGrid({ ... grid options ... });

Infragistics 然后在 内部呈现小部件div#myGrid,包括table#myGrid_table后代。这似乎是您需要指定以过滤网格的元素。

也就是说,您要调用由 igGrid 小部件呈现的内容,该小部件将具有igGridFiltering以下. 假设您以正确的格式提供了过滤器,这应该可以工作:tableid = id + '_table'myFilter

$('#myGrid_table').igGridFiltering("filter", myFilter);

至于 (a),是的,您确实需要重新创建网格,更新列,然后重新创建网格。

于 2019-07-15T14:28:38.943 回答