Jpl*_*us2 4 javascript jquery datatables datatables-1.10
这是我的数据表配置的示例
{
"dom" : "rltip",
"processing" : true,
"serverSide" : false,
"order" : [ [ 1 , "desc" ] ],
"searching" : false,
data: [
{ "column-a" : "Sample Data A" , "column-b" : 10 , "column-c" : "Blah Blah" },
{ "column-a" : "Sample Data B" , "column-b" : 5 , "column-c" : "Blah Blah" },
{ "column-a" : "Sample Data C" , "column-b" : 38 , "column-c" : "Blah Blah" }
],
"columnDefs" : [
{
"targets" : 0,
"orderable" : false,
"data" : "column-a"
},
{
"targets" : 1,
"orderable" : false,
"data" : "column-b"
},
{
"targets" : 2,
"orderable" : true,
"className" : "title",
"data" : "column-c"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想格式化显示的数据,但是在排序和其他与后端相关的东西上,我想使用原始的未格式化数据。
重要提示:我必须在客户端(javascript)上执行此操作。
我已经在columnDefs上尝试过渲染函数回调,但是它似乎不起作用。
"render" : function( data , type , row ) {
if ( type === "sort" )
return data;
// format data here
return data; // This is a formatted data
}
Run Code Online (Sandbox Code Playgroud)
我所说的“似乎不起作用”是指排序已损坏,它将考虑格式化的数据,而不仅仅是原始数据。
我找到了这篇旧的相关文章,但似乎不再适用于datatables.net的较新版本
我正在使用版本1.10.15
Shi*_*fty 11
该渲染功能与不同的值多次调用类型。如果将未格式化的数据仅设置为类型排序,则与排序相关的类型(如type)会遗漏其他数据。代替处理的情况下,型 显示器和用于在返回任何其它值未格式化的数据类型。
"render" : function( data , type , row ) {
if ( type === "display" )
{
// format data here
return data; // This is a formatted data
}
return data; // This is a unformatted data
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1995 次 |
| 最近记录: |