简体   繁体   English

Angular 2生命周期和VMware Clarity UI网格

[英]Angular 2 Lifecycle and VMware Clarity UI Grid

I'm making a rest call inside of a component. 我正在组件内部进行休息调用。 I'm rendering the data in a clr-datagrid. 我在clr-datagrid中渲染数据。 When it is first rendered, the data is skewed and misaligned. 首次渲染时,数据会偏斜并且不对齐。 If I sort the data, or do anything on the grid, the data becomes properly aligned. 如果我对数据进行排序,或对网格执行任何操作,则数据会正确对齐。 I'm assuming this is due to the grid not having all of the data in time to calculate the proper column widths. 我假设这是由于网格没有及时的所有数据来计算正确的列宽。 I'm making the REST call inside of the constructor, though I've also tried moving this into the ngOnInit() function with no improvement. 我正在构造函数内部进行REST调用,尽管我也尝试将其移入ngOnInit()函数而没有任何改进。

Where is the recommended location for a REST call in a component? 组件中REST调用的推荐位置在哪里? Once the data is properly returned, is there something I need to call to cause the UI to "refresh" it calculations on widths? 一旦数据被正确返回,我需要调用什么来使UI在宽度上“刷新”它的计算?

Because this code is making a REST call to an internal server, I am unable to provide a Plunker reproducing it. 因为此代码正在对内部服务器进行REST调用,所以我无法提供再现它的Plunker。

Component code: 组件代码:

export class NodesComponent implements OnInit {

nodes: Node[] = [];
currentNode: Node;

constructor(private dataService: DataService) {
    this.dataService.getNodes().subscribe(nodesAsJson => {
        for (let nodeAsJson of nodesAsJson) {
            let node: Node = new Node(nodeAsJson);
            this.nodes.push(node);
        }
    });
}

HTML Code HTML代码

<h4><clr-icon shape="server" size="24"></clr-icon>Nodes ({{ nodes.length }})</h4>
<clr-datagrid>
    <clr-dg-column [clrDgField] = "'id'">ID</clr-dg-column>
    <clr-dg-column [clrDgField] = "'name'">Name</clr-dg-column>
    <clr-dg-column [clrDgField] = "'type'">Type</clr-dg-column>

    <clr-dg-row *clrDgItems="let node of nodes">
        <clr-dg-cell>{{ node.id }}</clr-dg-cell>
        <clr-dg-cell>{{ node.name }}</clr-dg-cell>
        <clr-dg-cell>{{ node.type }}</clr-dg-cell>
    </clr-dg-row>
    <clr-dg-footer>
        {{pagination1.firstItem + 1}} - {{pagination1.lastItem + 1}} of     {{pagination1.totalItems}} Nodes
        <clr-dg-pagination #pagination1 [clrDgPageSize]="5"></clr-dg-pagination>
</clr-dg-footer>

Misaligned Grid after rest call is made 休息呼叫后,网格未对齐 休息呼叫后,网格未对齐

Aligned properly after clicking header sort 单击标题排序后正确对齐 单击标题排序后正确对齐

This looks to me like one of these two issues: 这看起来像是这两个问题之一:
https://github.com/vmware/clarity/issues/623 https://github.com/vmware/clarity/issues/623
https://github.com/vmware/clarity/issues/817 https://github.com/vmware/clarity/issues/817

Both have been solved as part of Clarity 0.9.14. 两者都已作为Clarity 0.9.14的一部分得到解决。 Which version are you using? 你使用的是哪个版本? If it's a later version, could you reproduce your use case on a plunker and file for a bug on Clarity's GitHub? 如果它是更高版本,您是否可以在一个plunker上重现您的用例并提交Clarity GitHub上的错误文件 . Thanks! 谢谢! The expected behavior is that column widths are only calculated once the data is ready. 预期的行为是列宽仅在数据准备好后计算。

Check the console for javascript errors. 检查控制台是否有javascript错误。 I have found when using the datagrid if the data isnt fully loaded yet, you are probably accessing a property or a function of an object that doesnt exist. 我发现在使用datagrid的时候,如果数据还没有完全加载,你可能正在访问一个属性或一个不存在的对象的函数。 This will throw an error which the datagrid seems to halt on causing the skewing. 这将抛出一个错误,数据网格似乎停止导致倾斜。 Maybe initialize your data fields with somethings (even if empty) to avoid these errors. 也许用某些东西初始化你的数据字段(即使是空的)以避免这些错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM