0

I'm developing app with Angular 2 + Kendo UI.

So, I have array of paths to images and I want to show it in table form. I want instead of 1 column in a table row show 5 columns in a table row.

Can I do that? If yes, then how would look kendo grid html template and data for it?

3
  • Not sure about Angular implementation, but it is possible to construct a column array based on an array in JS.. Should just be a case on combining a column template implementation along with this. Here is an article about hyperlinks within the template aswell. And here is an example using Angular2. Hope this helps Commented Jun 2, 2017 at 14:23
  • What data do you want the five columns to contain? Commented Jun 4, 2017 at 9:52
  • I want to place there string 'url'. Commented Jun 5, 2017 at 10:18

1 Answer 1

1

So, the result is the following:

HTML template (table header is hidden):

<kendo-grid [data]="gridData">
    <ng-template ngFor [ngForOf]="columns" let-column>
        <kendo-grid-column field="{{column}}" [headerClass]="'hidden'">
            <ng-template kendoGridCellTemplate let-dataItem>
                <img *ngIf="dataItem[column].avatarUri != null" [src]="dataItem[column].avatarUri" [alt]="dataItem[column].keywords" />
             </ng-template>
        </kendo-grid-column>
    </ng-template>
</kendo-grid>

TypeScript component:

gridData: any[];
columns: string[] = ["column0", "column1", "column2", "column3", "column4"];

ngOnInit() {
    this.avatarService.getAvatars()
        .subscribe((avatars: Array<Avatar>) => {
            this.gridData = [];
            let i = 0;
            while (i < avatars.length) {
                let obj = {};
                for (let column of this.columns) {
                    obj[column] = {
                        avatarUri: i >= avatars.length ? null : avatars[i].avatarUri,
                        keywords: i >= avatars.length ? null : avatars[i].keywords
                    };
                    i++;
                }
                this.gridData.push(obj);
            }
        });
}

Also helped that link with dynamic columns.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.