Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Center Align ng-Table Header?

All , I am using ng-table for the Grid. I am using following code snippet to set the column .

<td data-title="'Access ID'" sortable="'accessID'" style="width:120px" class="text-center">{{people.accessID}}</td>

enter image description here

But I am not able to center align the Column Header but column data.

Here is the source code snippet for Access ID Header.

<th ng-repeat="column in $columns" ng-class="{ 'sortable': parse(column.sortable), 'sort-asc': params.sorting()[parse(column.sortable)]=='asc', 'sort-desc': params.sorting()[parse(column.sortable)]=='desc' }" ng-click="sortBy(column, $event)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header  sortable"> <!-- ngIf: !template --><div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)" class="ng-binding ng-scope">Access ID</div><!-- end ngIf: !template --> <!-- ngIf: template --> </th>

Question is , How to center align the Header for a particular column in ng-table?

like image 518
ggn979 Avatar asked Mar 18 '15 17:03

ggn979


People also ask

How do you center align table headings?

To center align text in table cells, use the CSS property text-align. The <table> tag align attribute was used before, but HTML5 deprecated the attribute.

Should table headers be centered?

The source is a note left aligned at the bottom of the table used to identify the source of the information provided in the table. Column headings should be center aligned. 3 rules for a table: The main title should be centered, all caps, and bold. The horizontal arrangement of information in a table is a row.

How do I center a table header in bootstrap?

By adding the ” text-center” class of Bootstrap 3 We can use the “text-center” class of bootstrap 3 for the center-alignment of an element. So in our td when we add “text-center” class, and then our table text goes to the center.

How do I center align thead in HTML?

Using the <center></center> tags One way to center text or put it in the middle of the page is to enclose it within <center></center> tags.


3 Answers

The answer submitted by @OpenUserX03 is almost perfect, except you have to wrap the class name in single quotes, like so:

<td data-title="'Access ID'" sortable="'accessID'" style="width:120px" class="text-center" header-class="'text-center'">{{people.accessID}}</td>
like image 126
radius Avatar answered Oct 18 '22 07:10

radius


You can use the header-class attribute to set the class for - you guessed it - the header.

<td data-title="'Access ID'" sortable="'accessID'" style="width:120px" class="text-center" header-class="text-center">{{people.accessID}}</td>
like image 32
OpenUserX03 Avatar answered Oct 18 '22 08:10

OpenUserX03


i used to have the same issue how to align left my ng-table headers. on the documentation of ng-table it does not say anything nor at the examples.

you have two ways to do this the fast and the more 'professional'

fast way:

open files ng-table/dist/ng-table.css and ng-table.min.css, according on which css file you use. on the first line it manages the header,

.ng-table th {
  text-align: center;/*just change that parameter to left/right*/
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

'professional' way: create a custom style and add it to your website css file ,like this :

.table thead th {
  text-align: left;/*change that parameter to left/right*/
}

Hope helps, good luck.

like image 21
Theo Itzaris Avatar answered Oct 18 '22 09:10

Theo Itzaris