Skip to content

Center align content in data grid #605

Closed Answered by nzbin
rahulpd101 asked this question in Q&A
Discussion options

You must be logged in to vote

Define a class for some columns.

columns = [
  {
    header: 'Counter Number',
    field: 'counterDetails.CounterNo',
    class: (data) => {
      if (data == null) {
        return 'text-center'; // <= define a class
      } else {
        return data.counterDetails.CounterNo == 'Not Assigned' ? 'warning' : '';
      }
    },
    minWidth: 100,
    width: '100px',
  },
  ...
];

Then modify the CSS styles for the mtx-grid.

.text-center .mat-header-cell-inner {
  justify-content: center;
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by rahulpd101
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants