使用自定义sType从过滤器中去除HTML标记 [英] Strip HTML tags from filter with custom sType
本文介绍了使用自定义sType从过滤器中去除HTML标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据表,它被定义为
I have a datatable which is defined as
$('#group').dataTable( {
"sDom": '<"H"fi>t<"F">',
"aaSorting": [ [2,'asc'], [1,'asc'] ],
"aoColumnDefs": [
{"aTargets": [ 0 ], "sType": null, "bSortable": false, "bSearchable": false },
{"aTargets": [ 1, 2 ], "sType": "html", "asSorting": [ "asc", "desc" ] },
{"aTargets": [ 3 ], "sType": "gcse-grade", "asSorting": [ "desc", "asc" ] },
{"aTargets": [ "_all" ], "sType": "grade", "asSorting": [ "desc", "asc" ] }
],
"bAutoWidth": false,
"bFilter": true,
"bInfo": true,
"bLengthChange": false,
"bPaginate": false,
"bScrollAutoCss": true,
"bScrollCollapse": true,
"bSort": true,
"oLanguage": { "sSearch": "_INPUT_" }
}
);
正如您所看到的,我已经使用了名为 grade $ c的自定义sType $ c>和
gcse_grade
。我有自定义排序工作正常使用oSort。但是,当我创建表格时,这些列有时会在其中包含HTML标签。
As you can see I have used custom sTypes called grade
and gcse_grade
. I have custom sorting working fine using oSort. However, when I create the table these columns sometimes have HTML tags within them.
如何过滤这些内容以便首先从内部剥离HTML标签。即过滤器只看到文本,而不是标签(因为我不希望过滤器拿起任何或标签)。
How can I filter these so that it firstly strips the HTML tags from within. i.e. so the filter only sees the text, not the tags (as I don't want the filter to pick up any , or tags).
我有一个 fiddle here
I have a fiddle here
推荐答案
"aoColumnDefs": [
{ "aTargets": [0],
"mRender": function ( data, type, full ) {
if (type === 'filter') {
return data.replace(/(<([^>]+)>)/ig,"");
}
return data;
}
}
]
这篇关于使用自定义sType从过滤器中去除HTML标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文