如何在DataTables中使用搜索? [英] How to use search in DataTables?

查看:361
本文介绍了如何在DataTables中使用搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据表 [ ^ ]来绘制我的数据.我还使用OData过滤器,通过几种条件仅显示我需要的那些行.

I am using DataTables[^] to draw my data. Also I am using OData filter to show only those rows which I need, by several conditions.

var dtApi = new $.fn.dataTable.Api("#CardsGrid_grid");
...
filter assing (for example: "Status eq 0" and...)
...
dtApi.draw();


它工作正常.我收到了我需要的东西.现在,我只需要查找并显示那些值(其中之一)包含文本框中的值的行.

所以...根据此链接 [


It works fine. I am receiving what I need. Now I need find and show only those rows which values (one of them) contains a value from textbox.

So... according to this link[^],

column().search(value)

应该可以,而且应该这样做看起来像:

should do the thing, and this supposed to look like:

var search = $("#searchInTable").val();
dtApi.column().search(search).draw();


但事实是,这无能为力.完全没有.我以为我做错了,或者可能是因为我在使用OData(结果dtApi.rows().filter也对任何事情都没有反应).

如何正确使用搜索?


but the thing is that this do nothing. At all. I assume that I doing it wrong, or maybe because I am using OData (and as a result, dtApi.rows().filter also not reaction on anything).

How can I use search correctly?

推荐答案

.fn.dataTable.Api(" #CardsGrid_grid"); ... 过滤器匹配(例如, :" 和...) ... dtApi.draw();
.fn.dataTable.Api("#CardsGrid_grid"); ... filter assing (for example: "Status eq 0" and...) ... dtApi.draw();


它工作正常.我收到了我需要的东西.现在,我只需要查找并显示那些值(其中之一)包含文本框中的值的行.

所以...根据
此链接 [


It works fine. I am receiving what I need. Now I need find and show only those rows which values (one of them) contains a value from textbox.

So... according to this link[^],

column().search(value)

应该可以,而且应该这样做看起来像:

should do the thing, and this supposed to look like:

var search =


(" #searchInTable").val(); dtApi.column().search(search).draw();
("#searchInTable").val(); dtApi.column().search(search).draw();


但事实是,这无能为力.完全没有.我以为我做错了,或者可能是因为我在使用OData(结果dtApi.rows().filter也对任何事情都没有反应).

如何正确使用搜索?


but the thing is that this do nothing. At all. I assume that I doing it wrong, or maybe because I am using OData (and as a result, dtApi.rows().filter also not reaction on anything).

How can I use search correctly?




我没有使用过DataTables API(如您在上面发布的那样),但是如果您要搜索特定的列,那么我会这样做:

Hi,

I''ve not used the DataTables API (like you posted above), but if you are looking to search a specific column then I would do it like:

//Global variable for DataTable ... 
var dt;

//Create your DataTable ... 
function createDataTable(){
 dt =


这篇关于如何在DataTables中使用搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆