【发布时间】:2019-04-22 21:59:46
【问题描述】:
使用 DataTables 1.10.19 和 this plugin,我使用 alt 属性作为要排序的数据。
这行得通;
{
targets: [7],
type: 'alt-string',
render: function(data, type, row) {
if (data == 1) {
return '<a href="example.com"><i class="icon-ok" alt="Processed"></i></a>';
}
}
}
这不起作用;
{
targets: [7],
type: 'alt-string',
render: function(data, type, row) {
if (data == 1) {
return '<a href="example.com?id=' + row[0] + '&approvalcode=' + row[9] + '"><i class="icon-ok" alt="Processed"></i></a>';
}
}
}
似乎不是当我添加row URL 查询字符串时,它会破坏alt 过滤器,尽管其他一切都按预期工作。
插件代码如下;
/**
* Sort on the 'alt' tag of images in a column. This is particularly useful if
* you have a column of images (ticks and crosses for example) and you want to
* control the sorting using the alt tag.
*
* @name Alt string
* @summary Use the `alt` attribute of an image tag as the data to sort upon.
* @author _Jumpy_
*
* @example
* $('#example').dataTable( {
* columnDefs: [
* { type: 'alt-string', targets: 0 }
* ]
* } );
*/
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"alt-string-pre": function ( a ) {
return a.match(/alt="(.*?)"/)[1].toLowerCase();
},
"alt-string-asc": function( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"alt-string-desc": function(a,b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
【问题讨论】:
标签: javascript jquery html datatables filtering