Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing space prefix when header class is function #138

Open
LeoVie opened this issue Jan 16, 2025 · 0 comments
Open

Missing space prefix when header class is function #138

LeoVie opened this issue Jan 16, 2025 · 0 comments

Comments

@LeoVie
Copy link

LeoVie commented Jan 16, 2025

This template code

<ngx-datatable-column name="name" [headerClass]="getHeaderClass" />

with

protected getHeaderClass() {
  return 'foo';
}

produces this result:

<datatable-header-cell role="columnheader" resizeable="" long-press="" draggable="" class="datatable-header-cell resizeablefoo sortable resizeable" ...>

There is a space missing between resizable and foo.

This only occurs when passing a function to [headerClass], that returns a string. Passing a string directly to the property as well as passing a function, that returns an object, does not lead to the error.

The issue lays in the header-cell.component.ts in get columnCssClasses:

if (this.column.headerClass) {
  if (typeof this.column.headerClass === 'string') {
    cls += ' ' + this.column.headerClass;
  } else if (typeof this.column.headerClass === 'function') {
    const res = this.column.headerClass({
      column: this.column
    });

    if (typeof res === 'string') {
      cls += res; // <-- Here is the error, this must be cls += ' ' + res
    } else if (typeof res === 'object') {
      const keys = Object.keys(res);
      for (const k of keys) {
        if (res[k] === true) {
          cls += ` ${k}`;
        }
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant