没有应用数千个分隔符

时间:2016-09-06 10:44:13

标签: datatables

我使用jQuery DataTable:

$(document).ready(function() {

  var table = $('#t_list').DataTable({

    "language": {
        "decimal": ",",
        "thousands": " ",
        "emptyTable": _getText("datatable.resultat.zero"),
        "info": _getText("datatable.zone.statut.info"),
        "infoEmpty": "",
        "infoFiltered": _getText("datatable.zone.statut.filtre"),
        "lengthMenu": _getText("datatable.zone.nb.affichage"),
        "loadingRecords": _getText("datatable.resultat.chargement"),
        "processing": _getText("datatable.resultat.processing"),
        "search": _getText("datatable.zone.filtre"),
        "zeroRecords": _getText("datatable.resultat.zero"),
        "paginate": {
            "first": _getText("datatable.btn.premier"),
            "previous": _getText("datatable.btn.prcdt"),
            "next": _getText("datatable.btn.svt"),
            "last": _getText("datatable.btn.dern")
        }
    },

    "pagingType": "full_numbers",

    "serverSide": true,

    "ajax": "<c:url value='/ajaxDataTableListUsers' />",

    "columns": [{
        "data": "username"
    }, {
        "data": "email"
    }, {
        "data": "salary"
    }, {
        "data": "id"
    }],

    "columnDefs": [{
        "targets": 2,
        "className": "alignDroite"
    }, {
        "targets": 3,
        "render": function(data, type, row, meta) {
            var client_noms = row.username; < c: url
            var = "url_edit"
            value = "/edit" / >
                var url_edit = "${url_edit}?id=" + data;
            return '<div style="text-align:center;"><a href="' + url_edit + '"><img src="resources/images/edit.png" /></a>&nbsp;' +
                '<a href="#" id="del_' + data + '" onclick="afficheDlg(\'' + data + '\',\'' + client_noms + '\')"><img src="resources/images/cross.png" /></a></div>';
        }
    }]

  });

});

如您所见,language选项中有参数。但在运行时,不应用格式:

enter image description here

那么为什么不应用格式化?

- 编辑 -

数据来源如下:

    @Override
    @Transactional
    public List<User> list(int start, int length, String search, int triIdx, String ordreTri) {
        Criteria criteres = sessionFactory.getCurrentSession().createCriteria(User.class);
        if (!search.equals("")) {
            if (NumberUtils.isNumber(search))
                criteres.add(Restrictions.like("salary", Double.parseDouble(search)));
            else
                criteres.add(Restrictions.like("username", search, MatchMode.ANYWHERE));
        }
        criteres.setFirstResult(start);
        criteres.setMaxResults(length);
        if (ordreTri.equals("asc")) {
            switch (triIdx) {
                case 0:
                    criteres.addOrder(Order.asc("username"));
                    break;
                case 1:
                    criteres.addOrder(Order.asc("email"));
                    break;
                case 2:
                    criteres.addOrder(Order.asc("salary"));
                    break;
                default:
                    criteres.addOrder(Order.asc("username"));
                    break;
            }
        } else {
            switch (triIdx) {
                case 0:
                    criteres.addOrder(Order.desc("username"));
                    break;
                case 1:
                    criteres.addOrder(Order.desc("email"));
                    break;
                case 2:
                    criteres.addOrder(Order.desc("salary"));
                    break;
                default:
                    criteres.addOrder(Order.desc("username"));
                    break;
            }
        }
        criteres.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        @SuppressWarnings("unchecked")
        List<User> listUser = (List<User>) criteres.list();
        return listUser;
    }

1 个答案:

答案 0 :(得分:2)

您不会显示数据来源。

Datatableshttps://datatables.net/manual/i18n)的文档说明在解析数据时会使用thousandsdecimal选项,以便排序可以正确进行。看起来Datatables不是为了格式化您的数据,只是解析它。您应该按照希望的格式格式化数据。