Support » Plugin: TablePress » search only exact table value

  • Resolved weborise

    (@josephthiery)


    Dear Tobias,

    First of all, thank you very much for your beautiful Tablepress plugin. I searched all over your Tablepress website and also on the first pages of the plugin support here on WordPress (when will they have a proper search within a specific plugin?) and couldn’t find an answer. My question is also about a search feature.

    On this site, hddwarrantydot com/test-page/, I tried to implement a Search that would only pull a row result when the complete serial number is added. I wouldn’t want someone to see someone else warranty just on a keystroke. I’d rather have a click-to-find the row that has the exact value. Ideally, this search would only look for the serial number column (first column), but that’s not the most important at the moment.

    If there is an easy solution, I’d sure be happy to know about it. If not, I’d sure be happy to add my vote for such a feature in your premium extension list 🙂

    All the best.

Viewing 14 replies - 16 through 29 (of 29 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ah, my bad. Empty filter words need special treatment. Please try again with the version from http://pastebin.com/8rf20vP1

    And yes, please uncheck the “Use DataTables” checkbox, as it will not be useful on a table with just one visible row.

    Regards,
    Tobias

    Wow, ok, the last bit you set me worked perfectly ! Thank you ver very much ! Now, for this and for the last question I have, please send me the price you want.

    I would like to include a sentence in case there is a wrong entry made ? Something like :

    else {
    echo “Please enter a valid serial number”;
    }

    You’ve done already a lot for me and I thank you very much for it. So I’ll sure want to thank you for your work. Please let me know by email the costs you estimate. Thank you.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    great to hear that this works, so far 🙂

    For the ability to show an error message: That’s rather tricky, as the Extension basically does not give feedback on whether something was found or not. I’ll have to think about this a bit. I’ll try to come up with a solution and send you an email!

    Regards,
    Tobias

    🙂 Thanks a bunch ! If you can’t find it no worries. I thank you vey much for all what you did so far !

    well, I mean “if you don’t have the time to look for it”. Of course, I never doubt you could do it. It’s just that sometimes things get time and we don’t have enough of it to do all what we want… That’s all I meant. Thank you Tobias, you really made my day easier !

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no, no worries. It’s not really a time issue, but more a problem of coming up with the right approach to implement this technically 🙂

    Regards,
    Tobias

    I see. Well, thanks for your time and effort !

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    I have now thought about this a bit, and the best approach seems to be to hook into another filter hook and check if there will be at least two rows in the table (the header row and at least one matching data row). If not, we’ll replace the shown table data with a single cell table that shows the desired error message.
    The PHP code for this is at http://pastebin.com/PhUmBBmc

    Please append this to your theme’s functions.php file to test it.

    Regards,
    Tobias

    Nice ! It works great indeed !

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    great! 🙂 Thanks for the confirmation!

    Best wishes,
    Tobias

    Well, thank you to you 🙂 Best wishes !

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for the kind words! 🙂

    Happy New Year!
    Tobias

    Hi Tobias,

    Im trying to filter exact word, for example one of the words isnt actually a word is “ss” but when i filter it with the “ss” it shows all the data.

    all the information is in the first column that need to be filter for example:

    (filter 1)
    ship | length | weight
    SS Mildred | 200ft | 30ton (this would be displayed as it matches “SS”)
    SS Morrison | 200ft | 30ton (this would be displayed as it matches “SS”)
    S davidson | 250ft | 37ton (this would not be displayed as it dont match “SS”)

    (filter 2)
    ship | length | weight
    SS | 200ft | 30ton (this would be displayed as it matches “SS”)
    SS Mildred | 200ft | 30ton (not be displayed as it dont exact match “SS”)
    SS Morrison | 200ft | 30ton (not be displayed as it dont exact match “SS”)
    S davidson | 250ft | 37ton (not be displayed as it dont exact match “SS”)

    Im currently using the title of the page to select the table id and the word to filter and have edited the page.php to store the following information.

    <?php $wordlist = array("words", "to", "exclude","");  
    $string = strtolower(get_the_title()); //lower case and pull the title
    foreach($wordlist as $word)
    $string = preg_replace("/". $word ."/", " ", $string);
    $string = preg_replace('/\s+/', '', $string);
    
    $tabletitle = current(explode(' ', get_the_title()));
    
    if (strtolower($tabletitle) == "word1") {
        $tableid = "1";
    } elseif (strtolower($tabletitle) == "word2") {
        $tableid = "2";
    } elseif (strtolower($tabletitle) == "word3") {
        $tableid = "3";
    }
    ?>

    Currently using and works with everything except the “SS” (pulls all info on table) but works with “Mildred” as the filter term.
    <?php tablepress_print_table( array( 'id' => $tableid, 'filter' => $string, ) ); ?>

    Tried using:
    <?php tablepress_print_table( array( 'id' => $tableid, 'filter' => $string, 'filter_full_cell_match' => 'true' ) ); ?>

    With the above this the table shows no data on any filter term.

    I would like to know how to filter exact text but allow contain of other words like example filter 1

    and

    I would like to know how to filter exact text like example filter 2

    Thanks in Advance

    P.S – I made a donation on the 17-6-2017 as I love the plugin and i have paid for other plugins with less user friendliness.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    From what I understand, the Shortcode

    <?php tablepress_print_table( array( 'id' => $tableid, 'filter' => $string, ) ); ?>
    

    should give you the results for “(filter 1)”.

    For “(filter 2)”, you’ll need a small modification:

    <?php tablepress_print_table( array( 'id' => $tableid, 'filter' => $string, 'filter_full_cell_match' => true ) ); ?>
    

    (filter_full_cell_match is a boolean parameter).

    If this does not work, I recommend to first try it statically (i.e. by directly trying the Shortcode in a page, to see if that works. If it does, there’s probably something wrong in your PHP code that parses the title.

    Regards,
    Tobias

Viewing 14 replies - 16 through 29 (of 29 total)
  • The topic ‘search only exact table value’ is closed to new replies.