Angular 9 / Typescript - Hiding columns

Angular 9 / Typescript - Hiding columns

RandomUser2RandomUser2 Posts: 3Questions: 2Answers: 0

I'm trying to hide a column. My file (component.ts) looks something like this:

myValues: any;  // Can it be DataTables.ColumnSettings = {} ?
dtOptions: DataTables.Settings {};
this.myValues = [ {data: 'valueId' }, {data, 'myValue'} ];
this.dtOptions = {
  ...
  columns: this.myValues,
  columnDefs: [ orderable: true, targets: [_all] }
  ...
};

In node modules -> @types -> datatables.net -> index.d.ts, there is a ColumnsSetting interface with a visible property. However, when adding that to the dtOptions object it raises an error; also it doesn't provide details on where to apply.

How can I hide the first column?

The references I've found on this site are only for JS. Is there a place where I can find documentation for TS?

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    edited July 2020

    myValues: any; // Can it be DataTables.ColumnSettings = {} ?
    columns: this.myValues,

    The columns docs state that it expects and array. Looks like you are trying to use an object.

    However, when adding that to the dtOptions object it raises an error

    What is the error?

    this.myValues = [ {data: 'valueId' }, {data, 'myValue'} ];

    Looks like you have a syntax error with {data, 'myValue'}. It should be a colon like this {data: 'myValue'}.

    The columnDefs.targets docs state that _all is to be a string. You should have targets: ["_all"].

    Kevin

This discussion has been closed.