javascript jQuery 数据表自定义排序和过滤
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16053164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery datatable custom sorting and filtering
提问by Bilal Fazlani
I am using jquery datatables in my MVC4 application. The most simple configuration of jquery datatables.
我在我的 MVC4 应用程序中使用 jquery 数据表。jquery数据表最简单的配置。
Infact, I have placed this small jquery snippet in my layout.cshtml file which will take care of all tables in my application without doing anything custom.
事实上,我已将这个小的 jquery 片段放在我的 layout.cshtml 文件中,它将处理我的应用程序中的所有表,而无需进行任何自定义操作。
$(".dataTable").dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers"
}).columnFilter();
this works perfectly when I format the table with <thead>, <tbody> and <tfoot>.
当我格式化表格时,这非常有效 <thead>, <tbody> and <tfoot>.
Here's the image :
这是图像:
Ofcourse, not everything will work work with this basic configuration.
当然,并非所有东西都适用于这种基本配置。
The problem
问题
The payment status column contains not just some text, it contains a span and a hidden dropdown list. on click of <td>
, The span gets hidden and dropdown becomes visible. on dropdown change it reverts back to a visible span and hidden dropdown.
付款状态列不仅包含一些文本,还包含一个跨度和一个隐藏的下拉列表。单击<td>
,跨度被隐藏,下拉菜单变得可见。在下拉列表更改时,它会恢复为可见的跨度和隐藏的下拉列表。
The code :
代码 :
<td class=" " paymentid="106">
<span>
Completed
</span>
<select name:"paymentstatus"="" style="display:none;" onchange="changepaymentStatus($(this).parent().attr('paymentId'),$(this).val(),10);">
<option value="0" selected="'selected'">Completed</option>
<option value="1">Pending</option>
<option value="2">Cancelled</option>
</select>
</td>
With all this mess present in the <td>
element, it is not able to filter at all (for that column and sorting works incorrectly (for that column).
由于<td>
元素中存在所有这些混乱,它根本无法过滤(对于该列和排序工作不正确(对于该列)。
采纳答案by Alex Cruddace
Hi take a look at this http://datatables.net/examples/plug-ins/sorting_sType.htmlthis will do the job for you.
嗨,看看这个http://datatables.net/examples/plug-ins/sorting_sType.html这将为您完成这项工作。