如何在ag-grid中将数据加载到rowData中?

时间:2019-04-10 14:43:06

标签: aurelia ag-grid

我的html类中包含以下代码:

<ag-grid-aurelia #agGrid class="ag-theme-balham" style="width: 100%; height: 350px;" #agGrid  grid-ready.call="onGridReady()"
                             grid-options.bind="filesThatAreMalwareOptions">

                <ag-grid-column header-name="date" field="date" width.bind="300"></ag-grid-column>
                <ag-grid-column header-name="fileHash" field="fileHash" width.bind="300"></ag-grid-column>
                <ag-grid-column header-name="fileName" field="fileName" width.bind="300"></ag-grid-column>
                <ag-grid-column header-name="fileSize" field="fileSize" width.bind="300"></ag-grid-column>
                <ag-grid-column header-name="mimeType" field="mimeType" width.bind="300"></ag-grid-column>
                <ag-grid-column header-name="Malware" field="Malware" width.bind="300"></ag-grid-column>
                <ag-grid-column header-name="Virustotal-Link" field="Virustotal-Link" width.bind="300"></ag-grid-column>
</ag-grid-aurelia>

以及我的TypeScript类中的以下代码:

filesThatAreMalwareOptions:GridOptions = {
      rowData:  []      
    };
getValueFromRequest(queryEndpoint){
        this.http
            .fetch(queryEndpoint, {
                mode: "cors"
            })
            .then(result => result.json()
            ).then(body => {
            if (queryEndpoint == "TestFileData"){
                this.filesThatAreMalwareOptions.rowData = JSON.parse(body);
            }
            });

如果我想从服务的端点加载数据,围栏将显示“无行显示”。如果我将rowData硬编码为:

filesThatAreMalwareOptions:GridOptions = {
      rowData:  [ {date: '02.04.1990', fileHash: 'X', fileName: 'X', fileSize: 3245, mimeType: 'PDF'}]
};

数据显示在网格中。从服务加载数据在哪里?

1 个答案:

答案 0 :(得分:1)

除了直接设置属性rowData之外,您还需要使用api调用:

this.filesThatAreMalwareOptions.api.setRowData(JSON.parse(body));

请参阅api参考: https://www.ag-grid.com/javascript-grid-api/