我最近开始使用Datatables进行表操作。
现在我想搜索带有alphabatic排序的表...
请检查HTML
<a href="#" class="te">A</a>
<a href="#" class="te">B</a>
<a href="#" class="te">C</a>
<a href="#" class="te">D</a>
<a href="#" class="te">E</a>
<a href="#" class="te">F</a>
<a href="#" class="te">G</a>
<a href="#" class="te">H</a>
<a href="#" class="te">I</a>
<a href="#" class="te">J</a>
和脚本
$(".te").click(function() {
oTable.fnFilter( $(this).text(),0,true);
return false;
});
效果很好,但问题是它使用通配符搜索表,
假设有“ASMI”,“ASKI”,“ASLI”,“BISLY”,“BIKLY”,“BALUU”等值......
当我使用fnFilter
A
作为字符串参数时,我得到的值为"ASMI","ASKI","ASLI","BALUU"
,因为值"BALUU"
包含单词A
,
但是如何使用第一个字符进行搜索:
因此,当我使用A
进行搜索时,我只需要"ASMI","ASKI","ASLI"
作为搜索结果。
我该怎么做?
答案 0 :(得分:0)
您可以使用带有数据表的正则表达式启用过滤.. here is an example
使用正则表达式启用过滤后,
如果你想用'A'搜索第一个字符,试试像@ a或^ A这样的类型搜索
在这里你可以找到关于regex(patern)