0

I create a datatable in angular with help of this package. I want to full empty colums with "-".

Suppose that i have a datatable like this

enter image description here

I want to detect empty columns and fill it with default content. I found defaultContent property but doesn´t work.

So the question is: Using this package how can i fill it empty columns with "-" string?

UPDATE: Add defaultContent. No works.

this.dtOptions = {
      order: [[0, "desc"]],
      pagingType: "full_numbers",
      pageLength: 10,
      sScrollX: "100%",
      responsive: true,
      processing: true,
      searching: true,
      defaultContent: "-", //I TRY THIS
      language: {...}
}
2
  • can you show what you have tried so far? Commented Sep 3, 2019 at 7:35
  • Question updated. Commented Sep 3, 2019 at 7:39

1 Answer 1

2

You can simply use || Operator for this purpose, no need for any other library

e.g:

<tbody>
  <tr *ngFor="let person of persons">
    <td>{{ person.id || '-' }}</td>
    <td>{{ person.firstName || '-' }}</td>
    <td>{{ person.lastName || '-' }}</td>
  </tr>
</tbody>

Here it will check if person dont has the specific attribute then it will just show -

OR

You can add columns with defaultContent in your options as:

columns: [
  {
    title: 'ID',
    data: 'id',
    defaultContent: '-'
  },
  {
    title: 'First name',
    data: 'firstName',
    defaultContent: '-'
  },
  {
    title: 'Last name',
    data: 'lastName',
    defaultContent: '-'
  }
]

Reference: https://github.com/l-lin/angular-datatables/issues/237

Sign up to request clarification or add additional context in comments.

3 Comments

Know this way but i search a more "automatic" way
actually you have to write these fields manually in html file so whats more effort in putting these || ? i would understand if these were generated automatically
@ElHombreSinNombre i updated my answer please check

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.