Insert newline in column label
In our app, there are cases where we need to have multi-line labels - so I tried this:
{ field:'pstId.mncId.name' displayName:"Municipality of\nselected Postal code" ...
...but this doesn't work - the column header displays a space instead of going to a new line. I also tried...
{ field:'pstId.mncId.name' displayName:"Municipality of<br>selected Postal code" ...
...and saw a literal <BR> there.
How can I create multi-line column labels in ng-grid?
Hi @ttsiodras,
I had the same requirement recently and this it what came up. I'm not sure of your real use case, so I'll try to cover 2 scenarios that I can think (They are mostly workarounds and not real ng-grid solutions...)
First scenario: One line per variable
Since you have access to cell template and header template, it is possible to customize it and add a
in to add a new line. See this plunker for an example: http://plnkr.co/edit/5xTUH9mFcc1bACnL8MYP?p=preview
As you can see, you can define your cellTemplates so they take an array or a Javascript object and add a new line between those 2. Cool thing is you can extract that string builder into an AngularJS factory or in external .html template and use $templateCache. Also, as a side note, for the header, it's the same thing, you simply need to use headerCellTemplate and modify the default value of that one.
** Sorting is still working, but it uses the first variable in order to achieve it, if you want fancy sort, you need to implement it.
** Filter doesn't work out of the box, you'll need to use an external filter (showColumnMenu: true, showFilter: true in gridOptions)
Second scenario: Use multiline inside the variable (you have newline inside your string variable) Again, we use the custom template, but this time, we will use ng-bind-html-unsafe (http://docs-angularjs-org-dev.appspot.com/api/ng.directive:ngBindHtmlUnsafe) to render html inside the string. Here is the plunker: http://plnkr.co/edit/6Wn4FOsDALgqX6WvCFT6?p=preview What you could do if you have \n, is to simply replace them with html markup. ** As a side note, ng-ng-bind-html-unsafe is suppose to change in future versions of AngularJS (it's already done in the RC2) ** Sorting and filtering are working since we have 1 variable
These are just ideas that I can think of, feel free to play with them and customize them as needed.
Thanks! All I needed was the pointer to headerCellTemplate.