Html.Grid right align data in column

空扰寡人 提交于 2019-12-05 01:28:57

问题


In an Html.Grid, how can we ensure that data in the column (e.g. currency amounts) gets right aligned?

Thanks.


回答1:


You mean in the MvcContrib Grid?

You could use something like:

column.For(x => x.Amount).Attributes(style => "text-align:right");

or more tidily you could set a class:

column.For(x => x.Amount).Attributes(@class => "right-align");

and set an appropriate style rule on that class.




回答2:


Here's what worked for me. Within the grids htmlAttributes assign the resulting table an id. In this example "gridT". In the CSS create a style for "#gridT", for the second column to align the text left.

@grid.GetHtml(
.
.
   htmlAttributes: new { id = "gridT" },
        columns: grid.Columns(
        grid.Column(columnName: "ID", header: "ID"),
        grid.Column(columnName: "Name", header: "Name")

<style>
    #gridT th:nth-child(2) {
            text-align: left;
    }
</style>

The second column "Name" will be left aligned.



来源:https://stackoverflow.com/questions/3518679/html-grid-right-align-data-in-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!