我使用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> ' +
'<a href="#" id="del_' + data + '" onclick="afficheDlg(\'' + data + '\',\'' + client_noms + '\')"><img src="resources/images/cross.png" /></a></div>';
}
}]
});
});
如您所见,language
选项中有千参数。但在运行时,不应用格式:
那么为什么不应用格式化?
- 编辑 -
数据来源如下:
@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;
}
答案 0 :(得分:2)
您不会显示数据来源。
Datatables
(https://datatables.net/manual/i18n)的文档说明在解析数据时会使用thousands
和decimal
选项,以便排序可以正确进行。看起来Datatables
不是为了格式化您的数据,只是解析它。您应该按照希望的格式格式化数据。