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>
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?
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.
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.
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.
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.
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>
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With