我最近开始使用Datatables进行表操作。
现在我想按字母顺序对表进行搜索...
请检查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“等...
当我使用带有A的fnFilter作为字符串参数时,我得到的值是"ASMI","ASKI","ASLI","BALUU",因为值"BALUU"包含单词A,
但是如何使用第一个字符进行搜索:
因此,当我使用A进行搜索时,我只需要"ASMI","ASKI","ASLI"作为搜索结果。
我该怎么做呢?
发布于 2012-02-08 23:43:44
您可以使用regex和datatables启用过滤。here is an example
在使用regex启用过滤之后,
如果你想搜索带有'A‘的第一个字符,只需尝试键入搜索,如^a或^A
在这里你可以找到关于regex (模式)的信息
https://stackoverflow.com/questions/9192780
复制相似问题