2

Have requirement like API gives few columns of data and I need to add some static data columns. Is there any way to add few columns dynamically passing below like { data: this.test1 },{ data: this.test2 }. I tried to add two columns but unable to fetch the data, getting blank cells.

  constructor(private http: HttpClient) {}
   public test1 =123;
   public test2 =234;

Initialization:

this.dtOptions = {
  pagingType: "full_numbers",
  pageLength: 10,
  scrollCollapse: true,
  processing: true,
  destroy: true,
  scrollY:'50vh',
  columns: [
    { title: '<input type="checkbox" />' },
    { data: "index" },
    { data: "firstname" },
    { data: "lastname" },
    { data: this.test1 },
    { data: this.test2 }
  ],

Stackblitz

1 Answer 1

2

You can set data to null and then use the defaultContent option.

Hard-coded in the column definition:

{ title: "Hard-Coded Data", data: null, defaultContent: "foo" }

Similar, but using a JavaScript variable - for example, var bar = 'baz';:

{ title: "Hard-Coded Data", data: null, defaultContent: bar }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.