how to Search 2 values on the same datatable
i'm trying to make my input Search field Searching for 2 values in 2 distinct columns at the same time in JS. i have started with 1 value Search with this code :
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
});
i have try column().search() but I couldn't get it to work properly:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.column([2,3]).search("boo", "New").draw();
});
I'm trying to filter into the table eg the gender and type, can you help me on that?
javascript jquery html
add a comment |
i'm trying to make my input Search field Searching for 2 values in 2 distinct columns at the same time in JS. i have started with 1 value Search with this code :
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
});
i have try column().search() but I couldn't get it to work properly:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.column([2,3]).search("boo", "New").draw();
});
I'm trying to filter into the table eg the gender and type, can you help me on that?
javascript jquery html
@Zim84 thank you very much for the help, I had not remembered to test that way
– DJ_cascurity
Jan 18 at 12:43
@Jordan Gray thanks for hellping, Now I understand how table.column () . search () works, tanks
– DJ_cascurity
Jan 18 at 12:44
add a comment |
i'm trying to make my input Search field Searching for 2 values in 2 distinct columns at the same time in JS. i have started with 1 value Search with this code :
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
});
i have try column().search() but I couldn't get it to work properly:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.column([2,3]).search("boo", "New").draw();
});
I'm trying to filter into the table eg the gender and type, can you help me on that?
javascript jquery html
i'm trying to make my input Search field Searching for 2 values in 2 distinct columns at the same time in JS. i have started with 1 value Search with this code :
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
});
i have try column().search() but I couldn't get it to work properly:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.column([2,3]).search("boo", "New").draw();
});
I'm trying to filter into the table eg the gender and type, can you help me on that?
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
});
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
});
$("#boo").click(function(){
var table = $('#table').DataTable();
table.column([2,3]).search("boo", "New").draw();
});
$("#boo").click(function(){
var table = $('#table').DataTable();
table.column([2,3]).search("boo", "New").draw();
});
javascript jquery html
javascript jquery html
asked Jan 18 at 12:20
DJ_cascurityDJ_cascurity
207
207
@Zim84 thank you very much for the help, I had not remembered to test that way
– DJ_cascurity
Jan 18 at 12:43
@Jordan Gray thanks for hellping, Now I understand how table.column () . search () works, tanks
– DJ_cascurity
Jan 18 at 12:44
add a comment |
@Zim84 thank you very much for the help, I had not remembered to test that way
– DJ_cascurity
Jan 18 at 12:43
@Jordan Gray thanks for hellping, Now I understand how table.column () . search () works, tanks
– DJ_cascurity
Jan 18 at 12:44
@Zim84 thank you very much for the help, I had not remembered to test that way
– DJ_cascurity
Jan 18 at 12:43
@Zim84 thank you very much for the help, I had not remembered to test that way
– DJ_cascurity
Jan 18 at 12:43
@Jordan Gray thanks for hellping, Now I understand how table.column () . search () works, tanks
– DJ_cascurity
Jan 18 at 12:44
@Jordan Gray thanks for hellping, Now I understand how table.column () . search () works, tanks
– DJ_cascurity
Jan 18 at 12:44
add a comment |
3 Answers
3
active
oldest
votes
Try using .columns instead of .column:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.columns([2,3]).search("boo", "New").draw();
});
See DataTables documentation here.
The function column().search()
will search a specific column whereas columns().search() allows you to search multiple columns as defined in your array.
EDIT
i just added a line on your exemple :
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
table.columns([2,3]).filter("boo", "New").draw();
});
thanks for the help, but now I have a new problem, if I select type1 then select type 2, when selecting again type 1 I no longer have information, it is as if it goes out of the table
– DJ_cascurity
Jan 18 at 13:00
Are you checking both table 2 and table 3 for both keywords "boo" and "New"?
– ChrisNaylor94
Jan 18 at 13:02
yes, i' doing "boo" and "New" on the first and "boo" and "close" on the second, but if i click again on the first i have no data
– DJ_cascurity
Jan 18 at 13:05
Perhaps try running the queries independently like Jordan Grey and Zim84 suggested? var search1 = table.colum(2).search('boo', 'New'); var search2 = table.colum(23).search('boo', 'close'); Then you could concatenate the vars and call .draw()
– ChrisNaylor94
Jan 18 at 13:09
see the edit please
– DJ_cascurity
Jan 18 at 13:17
|
show 1 more comment
Just search on 2 columns:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.column(2).search("male");
table.column(3).search("asia").draw();
});
shoud i apply a reload table before the filter?
– DJ_cascurity
Jan 18 at 17:16
Only if you wish to have the most current data, if you load the data from an external source. My tables always use an AJAX source. I only reload when I submit something to the server or if I expect something might have changed. But that depends on your usecases.
– Zim84
Jan 18 at 17:19
my datatable is in constant update by de users, so maby will be better, but how can i inside js. file refrshe the datatable?
– DJ_cascurity
Jan 18 at 17:23
add a comment |
The .draw()
function does not do anything you do not tell it to. In simple terms, you can run many different events then call them all with .draw()
. Like Zim84 suggested, you can search in the 2 different columns but on the first one, you wouldn't do .draw()
BUT you would call .draw()
on your second search.
So.. yes, doing something like
table.column(2).search("male");
table.column(3).search("asia").draw();
would work fine.
New contributor
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54253930%2fhow-to-search-2-values-on-the-same-datatable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try using .columns instead of .column:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.columns([2,3]).search("boo", "New").draw();
});
See DataTables documentation here.
The function column().search()
will search a specific column whereas columns().search() allows you to search multiple columns as defined in your array.
EDIT
i just added a line on your exemple :
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
table.columns([2,3]).filter("boo", "New").draw();
});
thanks for the help, but now I have a new problem, if I select type1 then select type 2, when selecting again type 1 I no longer have information, it is as if it goes out of the table
– DJ_cascurity
Jan 18 at 13:00
Are you checking both table 2 and table 3 for both keywords "boo" and "New"?
– ChrisNaylor94
Jan 18 at 13:02
yes, i' doing "boo" and "New" on the first and "boo" and "close" on the second, but if i click again on the first i have no data
– DJ_cascurity
Jan 18 at 13:05
Perhaps try running the queries independently like Jordan Grey and Zim84 suggested? var search1 = table.colum(2).search('boo', 'New'); var search2 = table.colum(23).search('boo', 'close'); Then you could concatenate the vars and call .draw()
– ChrisNaylor94
Jan 18 at 13:09
see the edit please
– DJ_cascurity
Jan 18 at 13:17
|
show 1 more comment
Try using .columns instead of .column:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.columns([2,3]).search("boo", "New").draw();
});
See DataTables documentation here.
The function column().search()
will search a specific column whereas columns().search() allows you to search multiple columns as defined in your array.
EDIT
i just added a line on your exemple :
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
table.columns([2,3]).filter("boo", "New").draw();
});
thanks for the help, but now I have a new problem, if I select type1 then select type 2, when selecting again type 1 I no longer have information, it is as if it goes out of the table
– DJ_cascurity
Jan 18 at 13:00
Are you checking both table 2 and table 3 for both keywords "boo" and "New"?
– ChrisNaylor94
Jan 18 at 13:02
yes, i' doing "boo" and "New" on the first and "boo" and "close" on the second, but if i click again on the first i have no data
– DJ_cascurity
Jan 18 at 13:05
Perhaps try running the queries independently like Jordan Grey and Zim84 suggested? var search1 = table.colum(2).search('boo', 'New'); var search2 = table.colum(23).search('boo', 'close'); Then you could concatenate the vars and call .draw()
– ChrisNaylor94
Jan 18 at 13:09
see the edit please
– DJ_cascurity
Jan 18 at 13:17
|
show 1 more comment
Try using .columns instead of .column:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.columns([2,3]).search("boo", "New").draw();
});
See DataTables documentation here.
The function column().search()
will search a specific column whereas columns().search() allows you to search multiple columns as defined in your array.
EDIT
i just added a line on your exemple :
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
table.columns([2,3]).filter("boo", "New").draw();
});
Try using .columns instead of .column:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.columns([2,3]).search("boo", "New").draw();
});
See DataTables documentation here.
The function column().search()
will search a specific column whereas columns().search() allows you to search multiple columns as defined in your array.
EDIT
i just added a line on your exemple :
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
table.columns([2,3]).filter("boo", "New").draw();
});
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
table.columns([2,3]).filter("boo", "New").draw();
});
$("#boo").click(function(){
var table = $('#table').DataTable();
table.search("boo").draw();
table.columns([2,3]).filter("boo", "New").draw();
});
edited Jan 18 at 13:18
DJ_cascurity
207
207
answered Jan 18 at 12:47
ChrisNaylor94ChrisNaylor94
1316
1316
thanks for the help, but now I have a new problem, if I select type1 then select type 2, when selecting again type 1 I no longer have information, it is as if it goes out of the table
– DJ_cascurity
Jan 18 at 13:00
Are you checking both table 2 and table 3 for both keywords "boo" and "New"?
– ChrisNaylor94
Jan 18 at 13:02
yes, i' doing "boo" and "New" on the first and "boo" and "close" on the second, but if i click again on the first i have no data
– DJ_cascurity
Jan 18 at 13:05
Perhaps try running the queries independently like Jordan Grey and Zim84 suggested? var search1 = table.colum(2).search('boo', 'New'); var search2 = table.colum(23).search('boo', 'close'); Then you could concatenate the vars and call .draw()
– ChrisNaylor94
Jan 18 at 13:09
see the edit please
– DJ_cascurity
Jan 18 at 13:17
|
show 1 more comment
thanks for the help, but now I have a new problem, if I select type1 then select type 2, when selecting again type 1 I no longer have information, it is as if it goes out of the table
– DJ_cascurity
Jan 18 at 13:00
Are you checking both table 2 and table 3 for both keywords "boo" and "New"?
– ChrisNaylor94
Jan 18 at 13:02
yes, i' doing "boo" and "New" on the first and "boo" and "close" on the second, but if i click again on the first i have no data
– DJ_cascurity
Jan 18 at 13:05
Perhaps try running the queries independently like Jordan Grey and Zim84 suggested? var search1 = table.colum(2).search('boo', 'New'); var search2 = table.colum(23).search('boo', 'close'); Then you could concatenate the vars and call .draw()
– ChrisNaylor94
Jan 18 at 13:09
see the edit please
– DJ_cascurity
Jan 18 at 13:17
thanks for the help, but now I have a new problem, if I select type1 then select type 2, when selecting again type 1 I no longer have information, it is as if it goes out of the table
– DJ_cascurity
Jan 18 at 13:00
thanks for the help, but now I have a new problem, if I select type1 then select type 2, when selecting again type 1 I no longer have information, it is as if it goes out of the table
– DJ_cascurity
Jan 18 at 13:00
Are you checking both table 2 and table 3 for both keywords "boo" and "New"?
– ChrisNaylor94
Jan 18 at 13:02
Are you checking both table 2 and table 3 for both keywords "boo" and "New"?
– ChrisNaylor94
Jan 18 at 13:02
yes, i' doing "boo" and "New" on the first and "boo" and "close" on the second, but if i click again on the first i have no data
– DJ_cascurity
Jan 18 at 13:05
yes, i' doing "boo" and "New" on the first and "boo" and "close" on the second, but if i click again on the first i have no data
– DJ_cascurity
Jan 18 at 13:05
Perhaps try running the queries independently like Jordan Grey and Zim84 suggested? var search1 = table.colum(2).search('boo', 'New'); var search2 = table.colum(23).search('boo', 'close'); Then you could concatenate the vars and call .draw()
– ChrisNaylor94
Jan 18 at 13:09
Perhaps try running the queries independently like Jordan Grey and Zim84 suggested? var search1 = table.colum(2).search('boo', 'New'); var search2 = table.colum(23).search('boo', 'close'); Then you could concatenate the vars and call .draw()
– ChrisNaylor94
Jan 18 at 13:09
see the edit please
– DJ_cascurity
Jan 18 at 13:17
see the edit please
– DJ_cascurity
Jan 18 at 13:17
|
show 1 more comment
Just search on 2 columns:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.column(2).search("male");
table.column(3).search("asia").draw();
});
shoud i apply a reload table before the filter?
– DJ_cascurity
Jan 18 at 17:16
Only if you wish to have the most current data, if you load the data from an external source. My tables always use an AJAX source. I only reload when I submit something to the server or if I expect something might have changed. But that depends on your usecases.
– Zim84
Jan 18 at 17:19
my datatable is in constant update by de users, so maby will be better, but how can i inside js. file refrshe the datatable?
– DJ_cascurity
Jan 18 at 17:23
add a comment |
Just search on 2 columns:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.column(2).search("male");
table.column(3).search("asia").draw();
});
shoud i apply a reload table before the filter?
– DJ_cascurity
Jan 18 at 17:16
Only if you wish to have the most current data, if you load the data from an external source. My tables always use an AJAX source. I only reload when I submit something to the server or if I expect something might have changed. But that depends on your usecases.
– Zim84
Jan 18 at 17:19
my datatable is in constant update by de users, so maby will be better, but how can i inside js. file refrshe the datatable?
– DJ_cascurity
Jan 18 at 17:23
add a comment |
Just search on 2 columns:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.column(2).search("male");
table.column(3).search("asia").draw();
});
Just search on 2 columns:
$("#boo").click(function(){
var table = $('#table').DataTable();
table.column(2).search("male");
table.column(3).search("asia").draw();
});
answered Jan 18 at 12:28
Zim84Zim84
2,6132235
2,6132235
shoud i apply a reload table before the filter?
– DJ_cascurity
Jan 18 at 17:16
Only if you wish to have the most current data, if you load the data from an external source. My tables always use an AJAX source. I only reload when I submit something to the server or if I expect something might have changed. But that depends on your usecases.
– Zim84
Jan 18 at 17:19
my datatable is in constant update by de users, so maby will be better, but how can i inside js. file refrshe the datatable?
– DJ_cascurity
Jan 18 at 17:23
add a comment |
shoud i apply a reload table before the filter?
– DJ_cascurity
Jan 18 at 17:16
Only if you wish to have the most current data, if you load the data from an external source. My tables always use an AJAX source. I only reload when I submit something to the server or if I expect something might have changed. But that depends on your usecases.
– Zim84
Jan 18 at 17:19
my datatable is in constant update by de users, so maby will be better, but how can i inside js. file refrshe the datatable?
– DJ_cascurity
Jan 18 at 17:23
shoud i apply a reload table before the filter?
– DJ_cascurity
Jan 18 at 17:16
shoud i apply a reload table before the filter?
– DJ_cascurity
Jan 18 at 17:16
Only if you wish to have the most current data, if you load the data from an external source. My tables always use an AJAX source. I only reload when I submit something to the server or if I expect something might have changed. But that depends on your usecases.
– Zim84
Jan 18 at 17:19
Only if you wish to have the most current data, if you load the data from an external source. My tables always use an AJAX source. I only reload when I submit something to the server or if I expect something might have changed. But that depends on your usecases.
– Zim84
Jan 18 at 17:19
my datatable is in constant update by de users, so maby will be better, but how can i inside js. file refrshe the datatable?
– DJ_cascurity
Jan 18 at 17:23
my datatable is in constant update by de users, so maby will be better, but how can i inside js. file refrshe the datatable?
– DJ_cascurity
Jan 18 at 17:23
add a comment |
The .draw()
function does not do anything you do not tell it to. In simple terms, you can run many different events then call them all with .draw()
. Like Zim84 suggested, you can search in the 2 different columns but on the first one, you wouldn't do .draw()
BUT you would call .draw()
on your second search.
So.. yes, doing something like
table.column(2).search("male");
table.column(3).search("asia").draw();
would work fine.
New contributor
add a comment |
The .draw()
function does not do anything you do not tell it to. In simple terms, you can run many different events then call them all with .draw()
. Like Zim84 suggested, you can search in the 2 different columns but on the first one, you wouldn't do .draw()
BUT you would call .draw()
on your second search.
So.. yes, doing something like
table.column(2).search("male");
table.column(3).search("asia").draw();
would work fine.
New contributor
add a comment |
The .draw()
function does not do anything you do not tell it to. In simple terms, you can run many different events then call them all with .draw()
. Like Zim84 suggested, you can search in the 2 different columns but on the first one, you wouldn't do .draw()
BUT you would call .draw()
on your second search.
So.. yes, doing something like
table.column(2).search("male");
table.column(3).search("asia").draw();
would work fine.
New contributor
The .draw()
function does not do anything you do not tell it to. In simple terms, you can run many different events then call them all with .draw()
. Like Zim84 suggested, you can search in the 2 different columns but on the first one, you wouldn't do .draw()
BUT you would call .draw()
on your second search.
So.. yes, doing something like
table.column(2).search("male");
table.column(3).search("asia").draw();
would work fine.
New contributor
New contributor
answered Jan 18 at 12:35
Jordan GrayJordan Gray
313
313
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54253930%2fhow-to-search-2-values-on-the-same-datatable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@Zim84 thank you very much for the help, I had not remembered to test that way
– DJ_cascurity
Jan 18 at 12:43
@Jordan Gray thanks for hellping, Now I understand how table.column () . search () works, tanks
– DJ_cascurity
Jan 18 at 12:44