EasyUI Forum
March 29, 2024, 01:50:47 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to automatically create grid columns according to server side tabular data?  (Read 5918 times)
softboy99
Newbie
*
Posts: 43


View Profile Email
« on: February 01, 2018, 01:28:15 AM »

How to automatically create grid columns according to server side tabular data?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: February 01, 2018, 02:44:15 AM »

You can create a service to get the column definitions from remote server, subscribe it and then create the datagrid component. Please refer to the code below:
Code:
import { Component } from '@angular/core';
import { DataService } from './data.service';

@Component({
  selector: 'app-root',
  template: `
    <eui-datagrid *ngIf="columns" style="height:250px"
        [pagination]="true"
        [data]="data"
        [total]="total"
        [pageNumber]="pageNumber"
        [pageSize]="pageSize">
      <eui-grid-column *ngFor="let col of columns" [field]="col.field" [title]="col.title"></eui-grid-column>
    </eui-datagrid>
  `,
  providers: [DataService]
})
export class AppComponent {
  columns = null;
  total: number = 0;
  pageNumber = 1;
  pageSize = 20;
  data = [];

  constructor(public dataService: DataService){}

  ngAfterViewInit() {
    this.dataService.getColumns().subscribe(columns => this.columns = columns);
    this.dataService.getData().subscribe((data) => {
      this.total = data.total;
      this.data = data.rows;
    });
  }
}
Logged
softboy99
Newbie
*
Posts: 43


View Profile Email
« Reply #2 on: February 01, 2018, 05:40:31 AM »

Hi,
Thanks. Sorry for the confusion, what i mean is to do that from one round trip to the server not first the columns and then data. 
« Last Edit: February 01, 2018, 06:00:26 PM by softboy99 » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!