Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to right align kendo grid numeric field column header?

I am using kendo grid. All my column headers are left aligned. I want the column headers having numeric data to be right aligned.Can anyone suggest anything ?

like image 372
Chidananda Behera Avatar asked Dec 06 '25 03:12

Chidananda Behera


2 Answers

There's already a configuration setting for that. columns.headerAttributes

like image 133
uygar donduran Avatar answered Dec 07 '25 23:12

uygar donduran


You can try using columns.headerTemplate property:

headerTemplate: kendo.template("<div class='header-right'>ColumnName</div>")

With header-right being:

.header-right {
    text-align: right
}

Working demo.

Cons:

  • You will have to set this template property to all your numeric columns;
  • You will have to set the column's name inside the template.

UPDATE

Found simple way of doing this with the following function:

var tmpl = function() {
    return kendo.template($("#javascriptTemplate").html())({ columnName: this.toString() });
};

This function just calls kendo.template and returns its results, passing an object to it with the column's name. It is used in the columns property like this:

{ field: "age", headerTemplate: tmpl.bind("Age") }

It becomes more elegant and readable in my opinion, and actually doens't differ so much from the common way to set the column title, as it would be set as title: "Age" after all.

And the template:

<script id="javascriptTemplate" type="text/x-kendo-template">
    <div class='header-right'>#:columnName#</div>
</script>

Working demo.

like image 28
DontVoteMeDown Avatar answered Dec 08 '25 00:12

DontVoteMeDown



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!