正确对齐数据表中的数字数据 [英] Giving right align to numeric data in datatables

查看:106
本文介绍了正确对齐数据表中的数字数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery-datatables。我希望如果值是数字,则其对齐方式应为正确;如果为字符串,则应对齐。

I am using jquery-datatables. I want that if the value is numeric its alignment should be right and if it is string then the alignment should be left. Is it possible with datatables or is there any method in it?

  <% @tasks.each do |task| -%> 
  <tr>
    <% col_order.each do |key| %>
      <td>
      <% value = task[key.column_name.split(" as ")[1]] || task[key.column_name.split(".")[1]] -%>
      <% if key["drilldown_reportid"].present? %>
        <%= link_to value, project_report_path(@current_project,key["drilldown_reportid"], :column=>"#{key.column_name}", :value=>"#{value}") %>
      <% else %>
        <%= value -%> </td>
      <% end %>
    <% end %>
  </tr>

  <% end -%>


推荐答案

我通过更改客户端代码(而不更改任何服务器端代码)。

I solved this problems by changing the client side code (not changing any server-side code).

在文件 css / jquery.dataTables.css中,
我添加了一个类

in file css/jquery.dataTables.css, I added a class

.alignRight { text-align: right; }

在我用于处理数据的JavaScript文件中,我更改了 aoColumnDefs ...

And in my javascript file for processing the data I changed "aoColumnDefs"...

///...
"aoColumnDefs" : [
//...col 1 -6
// col_07

{
    "aTargets" : [ 7 ],
    "fnRender" : function(oObj) {
            return Math.round(oObj.aData["endingDepth"] * 100) / 100;
    },
    "sTitle" : "Ending Depth [m]",
    "sWidth" : "5em",
    "sClass" : "alignRight"
},
//... more columns

这篇关于正确对齐数据表中的数字数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆