0

这应该很容易,但...

下面的代码工作得很好(我已经去掉了这里不需要的信息):

$(function() 
{
    .
    ..
    ...
    // Defining the data options.
    var datasetOptions = 
    {
        fields: fieldArray,
        recordType: 'array',
        data: rowData
    };

    // Putting together the column options.
    var columnOptions = new Array();
    for (var i = 0; i < fieldNames.length; i++)
    {
        columnOptions.push({id: fieldNames[i], header: fieldNames[i], width: columnWidth});
    }

    // Defining the grid options.
    var toolbar = 'filter state';
    var gridOptions =
    {
        id: 'SigmaGridID',
        container: 'SigmaGridDiv', 
        height: gridHeight,
        pageSize: rowCount,
        replaceContainer: true, 
        resizable: true,
        selectRowByCheck: false,
        showGridMenu : false,
        showIndexColumn: false,
        skin: "vista",
        toolbarContent: toolbar,
        toolbarPosition: 'bottom',
        width: gridWidth, 

        dataset: datasetOptions,
        columns: columnOptions
    };

    // Displaying the grid.
    var grid = new Sigma.Grid(gridOptions);
    Sigma.Util.onLoad(Sigma.Grid.render(grid)); 
});

当页面加载时,网格被填充并且一切都很好。但我不想每次都重新加载整个页面。

我成功地使用以下方法动态重新填充网格:

var grid = Sigma.$grid("SigmaGridID");
grid.refresh(rowData);
Sigma.Grid.render(grid);

但这不会调整列。因此,如果我要添加一列,则数据会更新,但缺少一列。如果我删除一列,则显示数据,但额外的列全部为空。

所以。如何调整列或有更好的方法来动态重新渲染和重新显示 Sigma 网格?换句话说,我们如何不仅在页面加载时显示 Sigma Grid?

谢谢。

迈克尔

4

1 回答 1

0

好吧,最后我找到了一些有用的东西。

当我想重新填充 Sigma Grid 时,我首先进行一些清理:

        Sigma.destroyGrids();
        gGrid = null;

        var oldSigmaGridDiv = document.getElementById("SigmaGridDiv");
        if (!isEmpty(oldSigmaGridDiv))
        {
            oldSigmaGridDiv.parentNode.removeChild(oldSigmaGridDiv);
        }

        var newSigmaGridDiv = document.createElement("div");
        newSigmaGridDiv.id = "SigmaGridDiv";
        var parentDiv = document.getElementById("SigmaGridParentDiv");
        parentDiv.appendChild(newSigmaGridDiv);

注意:gGrid 只是上面的“var grid”,我把 global 设置为 null (为了让垃圾收集器将其清除并确保我们使用新的内存空间)。

比我调用前面的代码(我把它放入一个能够随意调用它的函数)进行一次更改(最后):

    gGrid = new Sigma.Grid(gridOptions);
    if (pOnPageLoad)
    {
        Sigma.Util.onLoad(Sigma.Grid.render(gGrid));
    }
    else
    {
        gGrid.render();
    }

瞧!

此外,您可以专门针对单元格。下面是一些示例代码,它向您展示了我们正在更改列“ColumnA”的值以在 Sigma 网格中的所有选定行中包含一个新值:

var newValue = 'Some amazing new value';

var selectedRows = gGrid.selectedRows;
for (var i = 0; i < selectedRows.length; i++)
{
    // Retrieving the current selected row's index in the grid.
    var indexStr = selectedRows[i].getAttribute("__gt_ds_index__");

    // Changing the value.
    gGrid.setCellValue('ColumnA', parseInt(indexStr), newValue);
    gGrid.refreshRow(selectedRows[i]);
}

gGrid.reload();
于 2015-03-26T15:30:25.847 回答