Тип "Person []" нельзя назначить типу "ColumnSettings [] в Angular 7 Datatable - PullRequest
0 голосов
/ 22 мая 2019

Проблема

Тип «Person []» нельзя назначить типу «ColumnSettings []».

Тип «Person» не имеет общих свойств с типом «ColumnSettings».ts (2322)

Ожидаемый тип происходит из свойства 'columns', которое объявлено здесь в типе 'Settings'

i, за которым следует http://l -lin.github.io/angular-datatables/#/basic/server-side-angular-way

возникла проблема после добавления таблицы данных json.

Класс персонажа

export class Person {
id: number;
first_name: string;
last_name: string;
}

Угловой код

publicDeals: Person[] = [];

ngOnInit(): void {
const that = this;



this.abc();



console.log(this.publicDeals);

this.dtOptions = {
  pagingType: 'full_numbers',
  pageLength: 2,
  serverSide: true,
  processing: true,
  ajax: (dataTablesParameters: any, callback) => {
    that.httpClient
      .post<DataTablesResponse>(
        this.api_url,
        dataTablesParameters, {}
      ).subscribe(resp => {
        that.persons = resp.data;
        //console.log(resp);
        callback({
          recordsTotal: resp.recordsTotal,
          recordsFiltered: resp.recordsFiltered,
          data: [],

        });
      });
     },

   columns: that.publicDeals,


};


 }


   abc() {

return this.service.apifunc()
.subscribe(persons => {
  this.testts = TABLE_FIELDS;


   TABLE_FIELDS.forEach(element => {
    this.publicDeals.push(element);
   });
    this.dtTrigger.next();
});

}

Данные JSON

     TABLE_FIELD: [
        {
        data: "id"
        },
        {
        data: "first_name"
        },
        {
        data: "last_name"
        }

        ]
  • не может добавлять JSON в столбцы в датированном формате.

  • любая помощь приветствуется.

Ответы [ 2 ]

1 голос
/ 22 мая 2019

this.dtOptions.columns является type из ColumnSettings[] См. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e01d6e7abb2343c6b845d4945a368ed55cbf5bd2/types/datatables.net/index.d.ts#L1309

но вы передаете Person[], поэтому компилятор машинописи выдает ошибку.

Вы должны изменить данные, прежде чем перейти к this.dtOptions.columns.

0 голосов
/ 23 мая 2019

Решение, которое сработало

this.abc();

this.p_col = this.publicDeals;

this.dtOptions = {
  pagingType: 'full_numbers',
  pageLength: 2,
  serverSide: true,
  processing: true,
  ajax: (dataTablesParameters: any, callback) => {
    that.httpClient
      .post<DataTablesResponse>(
        this.api_url,
        dataTablesParameters, {}
      ).subscribe(resp => {
        that.persons = resp.data;

        callback({
          recordsTotal: resp.recordsTotal,
          recordsFiltered: resp.recordsFiltered,
          data: [],

        });
      });
  },

  columns: this.p_col,


};
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...