首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular-SlickGrid页脚显示不正确

Angular-SlickGrid页脚显示不正确
EN

Stack Overflow用户
提问于 2019-04-25 22:45:26
回答 1查看 451关注 0票数 0

我有一个Angular 7网站,我正在使用angular-slickgrid组件。我在页脚显示总计数时遇到了问题。

它显示的不是文本"Items per Page“和项目的实际总数,而是我假设的变量名称。

代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Column, FieldType, Filters, Formatters, GridOdataService, GridOption, Statistic } from 'angular-slickgrid';
import { GridHelper } from 'src/app/core/helpers/gridHelper/grid-helper';
import { EbPagination } from 'src/app/core/models/eb-pagination';
import { AuthenticationService } from 'src/app/Services/Authentication/authentication.service';
import { PolicyService } from 'src/app/Services/Policy/policy.service';
import { Policy } from '../../models/policy.model';


@Component({
  selector: 'app-policy-search',
  templateUrl: './policy-search.component.html',
  styleUrls: ['./policy-search.component.sass']
})
export class PolicySearchComponent implements OnInit {
  policies: Policy[];
  columnDefs: Column[] = [];
  gridOptions: GridOption = {};
  statistics: Statistic;
  pagination: EbPagination;
  odataQuery: '';

  constructor(
    private authService: AuthenticationService,
    private policyService: PolicyService,
    private router: Router) { }

  ngOnInit() {
    this.columnDefs = [
      { id: 'policyOrQuote', name: "Policy or Quote", field: "PolicyOrQuote", sortable: true, filterable: true },
      { id: 'PolicyReference', name: "Policy Reference", field: "PolicyReference", sortable: true, filterable: true },
      { id: 'Version', name: "Version", field: "Version", sortable: true, filterable: true },
      { id: 'MaxVersion', name: "Max Version", field: "MaxVersion", sortable: true, filterable: true },
      {
        id: 'IsLatest', name: "Is Latest Version", field: "IsLatest", formatter: Formatters.yesNo, sortable: true, type: FieldType.boolean,
        filterable: true,
        filter: {
          collection: [{ value: '', label: 'All' }, { value: true, label: 'Yes' }, { value: false, label: 'No' }],
          model: Filters.singleSelect,
          searchTerms: [],
          filterOptions: {
            offsetLeft: 14,
            width: 100
          },
        }
      },
      { id: 'ProcessingUnit', name: "Processing Unit", field: "ProcessingUnit", sortable: true, filterable: true },
      { id: 'ProfitCentre', name: "Profit Centre", field: "ProfitCentre", sortable: true, filterable: true },
      { id: 'InceptionDate', name: "Inception Date", field: "InceptionDate", formatter: Formatters.dateIso, sortable: true, filterable: false },
      { id: 'CancelledDate', name: "Cancelled Date", field: "CancelledDate", formatter: Formatters.dateIso, sortable: true, filterable: false },
      { id: 'LastModifiedDate', name: "LastModified Date", field: "LastModifiedDate", formatter: Formatters.dateTimeIso, sortable: true, filterable: false },
    ];

    this.gridOptions = {
      pagination: {
        pageSizes: [10, 15, 20, 25, 50, 100],
        pageSize: 25,
        totalItems: 0,
      },
      backendServiceApi: {
        service: new GridOdataService(),
        process: (query) => this.getData(query),
        postProcess: (response) => {
          this.statistics = response.statistics;
          this.getDataCallback(response);
        }
      }
    };
  }

  getData(query: string) {
    let gridHelper = new GridHelper();
    let filterString = gridHelper.buildFilter(query);
    return this.policyService.loadPolicies(gridHelper.pageNumber, gridHelper.pageSize, filterString);
  }

  getDataCallback(response) {
    let gridHelper = new GridHelper();
    this.pagination = gridHelper.extractPaginationFromHeader(response);

    this.gridOptions.pagination.totalItems = this.pagination.totalCount;
    if (this.statistics) {
      this.statistics.totalItemCount = this.pagination.totalCount;
      this.statistics.itemCount = response.body.count;
    }
    this.gridOptions = Object.assign({}, this.gridOptions);
    this.policies = response.body;
    this.odataQuery = response['query'];
  }
}

模板:

代码语言:javascript
复制
<div class="row">
    <div class="col-2">
        <h4>Filter</h4>
        <div class="row">
            <div class="btn-group">
                <button class="btn btn-primary" (click)="refresh()">Refresh</button>
            </div>
        </div>
    </div>
    <div class="col-10">

        <div class="card">
            <div class="card-header">Policy search</div>
            <div class="card-body">
                <angular-slickgrid gridId="grid1" [columnDefinitions]="columnDefs" [gridOptions]="gridOptions" [dataset]="policies">
                </angular-slickgrid>
            </div>
        </div>

    </div>
</div>

如果有人知道出了什么问题,我将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-26 23:12:27

我通过查看网格的代码解决了我的问题。事实证明,网格使用ngx-translate来显示和填充这些字符串。

我还没有设置翻译。一旦我把它设置好了,它就都能工作了。因此,在我的例子中,是用户无法正确地使用RTFM (或wiki)。:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55852029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档