how to Search 2 values on the same datatable












1















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?










share|improve this question























  • @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
















1















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?










share|improve this question























  • @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














1












1








1








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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



















  • @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












3 Answers
3






active

oldest

votes


















1














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();
});








share|improve this answer


























  • 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



















0














Just search on 2 columns:



$("#boo").click(function(){
var table = $('#table').DataTable();
table.column(2).search("male");
table.column(3).search("asia").draw();
});





share|improve this answer
























  • 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



















0














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.






share|improve this answer








New contributor




Jordan Gray is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    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();
    });








    share|improve this answer


























    • 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
















    1














    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();
    });








    share|improve this answer


























    • 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














    1












    1








    1







    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();
    });








    share|improve this answer















    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();
    });






    share|improve this answer














    share|improve this answer



    share|improve this answer








    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



















    • 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













    0














    Just search on 2 columns:



    $("#boo").click(function(){
    var table = $('#table').DataTable();
    table.column(2).search("male");
    table.column(3).search("asia").draw();
    });





    share|improve this answer
























    • 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
















    0














    Just search on 2 columns:



    $("#boo").click(function(){
    var table = $('#table').DataTable();
    table.column(2).search("male");
    table.column(3).search("asia").draw();
    });





    share|improve this answer
























    • 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














    0












    0








    0







    Just search on 2 columns:



    $("#boo").click(function(){
    var table = $('#table').DataTable();
    table.column(2).search("male");
    table.column(3).search("asia").draw();
    });





    share|improve this answer













    Just search on 2 columns:



    $("#boo").click(function(){
    var table = $('#table').DataTable();
    table.column(2).search("male");
    table.column(3).search("asia").draw();
    });






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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



















    • 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











    0














    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.






    share|improve this answer








    New contributor




    Jordan Gray is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.

























      0














      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.






      share|improve this answer








      New contributor




      Jordan Gray is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.























        0












        0








        0







        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.






        share|improve this answer








        New contributor




        Jordan Gray is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.










        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.







        share|improve this answer








        New contributor




        Jordan Gray is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        Jordan Gray is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered Jan 18 at 12:35









        Jordan GrayJordan Gray

        313




        313




        New contributor




        Jordan Gray is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Jordan Gray is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Jordan Gray is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Liquibase includeAll doesn't find base path

            How to use setInterval in EJS file?

            Petrus Granier-Deferre