统计-table、grid

grid

 <nz-spin [nzSpinning]="isSearch " [nzIndicator]="indicatorTemplate">
                    <ngx-grid #grid [settings]="settings" [source]="source" [isFieldSelection]="true">
                    </ngx-grid>
                </nz-spin> 
 public isSearch: boolean = false;
  @ViewChild("grid", { static: false }) grid: YzNgxGridComponent;
  public source = [];
  public gridOptions = null;
  public settings: {
    headerName?: string,
    field?: string,
    sort?: string
  }[] = [];
  search() {
    let statisticsData
    this.settings = [];
    this.isSearch = true;
    this.statisticsService.statistic().toPromise().then(GridInfo => {
      statisticsData = GridInfo;
      // console.log(GridInfo)
      GridInfo.forEach((info, i) => {
        //拼接表格标题栏
        if (i == 0) {
          for (let key = 0; key < info.split(",").length; key++) {
            if (info.split(",")[key] == "要素类型" || info.split(",")[key] == "分辨率" || info.split(",")[key] == "年份" || info.split(",")[key] == "月份") {
              continue;
            }
            this.settings.push({
              headerName: info.split(",")[key],
              field: key.toString(),
              sort: null
            })
          }
          return
        }
      })
    }).catch(() => {
      this.isSearch = false;
      this.message.error(this.type + "数据获取失败");
      return;
    }).then(() => {
      if (statisticsData == undefined) return
      this.source = [];
      //拼接表格body
      statisticsData.split("\r\n").forEach((info, i) => {
        if (i != 0) {
          let item: {} = []
          for (let key = 0; key < info.split(",").length; key++) {
            item[key] = info.split(",")[key]
          }
          this.source.push(item)
        }
      })
      this.isSearch = false;
      this.source.pop()
    })
  }

table

<nz-spin [nzSpinning]="isScaleStatistics">
        <nz-table *ngIf="!isScaleStatistics" #columnTable [nzData]="listOfStatistics" [nzScroll]="{ x: '300px' }">
            <thead>
                <tr>
                    <th nzWidth="100px" nzLeft="0px"></th>
                    <th nzWidth="100px" nzLeft="100px">描述</th>
                    <th *ngFor="let data of columnTable.data[0].header">{{data}}</th>
                </tr>
            </thead>
            <tbody>
                <tr *ngFor="let data of columnTable.data[0].body">
                    <td nzLeft="0px">{{ data.value }}</td>
                    <td nzLeft="100px">{{ data.text }}</td>
                    <td *ngFor="let data of data.province">{{data}}</td>
                </tr>
            </tbody>
        </nz-table>
    </nz-spin>
handleOk(): void {
    this.isAreaVisible = false;
    this.listOfStatistics = [{ header: [], body: [] }];
    this.isScaleStatistics = true;
    this.typeChange.emit(true)
    this.gisService.statisticByLevel(this.levels, this.where, this.levelParams.img)
      .subscribe((data) => {
        let areaData: Array<any> = [];
        //翻译表格header 区域
        for (let j in data) {
          if (j == "province") continue;//选择区域为省 删去重复列
          this.listOfStatistics[0].header.push(this.cCodeToProvName((j).length == 6 ? Number(j) : this.selArea.cCode))
        }
        //特殊区域放在前列
        let key = this.listOfStatistics[0].header[this.listOfStatistics[0].header.length - 1]
        this.listOfStatistics[0].header.splice(this.listOfStatistics[0].header.length - 1, 1);
        this.listOfStatistics[0].header.unshift(key)
        //拼接表格body数组
        this.scaleData.forEach(item => {
          for (let j in data) {
            for (let k in data[j]) {
              if (j == "province") continue;//选择区域为省 删去重复列
              if (k.split(',')[0] == item.value) {
                areaData.push(data[j]["total"] == 0 || data[j][k] == 0 ? 0 : ((data[j][k] / data[j]["total"]) * 100).toFixed(3) + "%");
                continue;
              }
            }
          }
          let b = areaData[areaData.length - 1]
          areaData.splice(areaData.length - 1, 1);
          areaData.unshift(b)
          this.listOfStatistics[0].body.push({ value: item.value, text: item.text, province: areaData })
          areaData = []
        })
        this.isScaleStatistics = false;

      }, e => {
        this.isScaleStatistics = false;
        this.message.error("等级比例面积统计数据获取失败")
      })
  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值