• Resolved TodayOnly

    (@todayonly)


    Hi Tobias,

    I managed to get my TablePress to filter through /?table_filter=keyword1+keyword2, but I am struggling to add additional shortcode filters acting simultaneously. Say I’d also like to filter on keyword3 in the column, whilst keeping the keyword1+keyword2 filter.

    I’ve tried searching but coudlnt’d find. However I have understand this would be possible thought custom JS code that uses the API. Is that the only solution, if so, could you link me to where there′s a explanation of integrating with the API?

    https://www.ads-software.com/plugins/tablepress/

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    This filtering mechanism does not use any DataTables functions, so that you won’t need to deal with the API.

    Instead, you should only need some changes in the PHP code of the Shortcode Filter from GET parameter Extension.
    There, it might be sufficient to adjust the line

    $attributes['filter'] = $filter_term;

    to

    if ( ! empty( $attributes['filter'] ) ) {
      $attributes['filter'] .= ' ';
    }
    $attributes['filter'] .= $filter_term;

    (This would append keyword1+keyword2, so that you would filter for

    keyword1 keyword2 keyword3

    Regards,
    Tobias

    Thread Starter TodayOnly

    (@todayonly)

    Hi Tobias,

    Thank you for the help.

    I am not exactly what you mean by that the keyword would be appended. Say for example that the user clicks a URL filter such as example.com/?table_filter=keyword1+keyword2 and then later the user clicks on the same page example.com/?table_filter=keyword3, would they all 3 be sorted then?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    sorry, that’s not really going to work like that, I’m afraid. If a user clicks the new link, the other filter words would be stripped (unless you dynamically create the link).

    Instead of using the Row Filter Extension (and the Filter from GET parameter Extension), you might therefore want to use the JavaScript filtering that is available via the search field above the table. For that, you could then also use the Extension from https://tablepress.org/extensions/datatables-button-filter/ to add filtering with buttons.

    Regards,
    Tobias

    Thread Starter TodayOnly

    (@todayonly)

    Hi Tobias,

    The JavaScript solution filtered very quickly and is to prefer.

    However, as of now it also ignores if a button has been already been clicked. I believe editing some PHP file would make that the filter term from previous button-click don’t get stripped, am I mistaken?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    yes, this would require modified JavaScript code in the PHP file.
    Basically, the line

    {$name}.search( $( this ).data( 'filterterm' ) ).draw();

    would need to be extended to read the current filter value from the text field first and append the extra one to that.

    Regards,
    Tobias

    Thread Starter TodayOnly

    (@todayonly)

    Hi Tobias,

    I looked into extending that line, but it’s hard.

    Do you know someone who previously managed to pull this off?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no, sorry, I’m not aware of users who have modified this before. Something like this should maybe work:

    {$name}.search( $( '#tablepress-{$table_id}_filter input' ).val() + ' ' + $( this ).data( 'filterterm' ) ).draw();

    Regards,
    Tobias

    Thread Starter TodayOnly

    (@todayonly)

    Hi Tobias,

    Thank you for the help. It worked wonderfully!

    Now I wonder, what is the query I’d enter in the shortcode to reset filters?

    <button class="table-123-filter" data-filterterm="ENTER HERE">Button text</button>

    Thank you again!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    good to hear that this helped!

    Resetting is not directly possible with just HTML, but would require even more JS, basically a call of the function with an empty string. So, you could try replacing

    $( '#tablepress-{$table_id}_filter input' ).val() + ' ' + $( this ).data( 'filterterm' )

    with a variable that you set to that value by default, or that you set to an empty string, if a special/custom filter term is passed.

    Regards,
    Tobias

    Thread Starter TodayOnly

    (@todayonly)

    Hi Tobias,

    I am very thankful for you helping me with this.

    For this solution, I tried Googling to find a variable that set a default value, but couldn’t manage to find one.

    It is quite essential to remove filters, or the user gets stuck.

    Could you think of another solution, in case you neither can’t find the Javascript variable?

    You are the best.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    it’s not about “finding” the JavaScript variable, it’s about modifying this JS code with one, i.e. you will need custom programming here.

    Regards,
    Tobias

    Thread Starter TodayOnly

    (@todayonly)

    Hi Tobias,

    Thank you for the insight.

    I was thinking then, an alternative solution, would be that when clicking at the button again, that filter gets deleted. Do you know a way to do that?

    Best regards

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    that’s exactly what I mean and what that code would achieve ??
    It’s just that I’m pretty busy at the moment, so that I don’t have time to develop such customizations in the frame of the free support that I can offer here in the forums.
    That’s why I was suggesting that you try implementing this yourself, first.

    Regards,
    Tobias

    Thread Starter TodayOnly

    (@todayonly)

    Hi Tobias,

    I hired a programmer, and he tried adding various codes such as
    var clear = “”;
    var remove = 0;

    to insert them as variables in the
    $( '#tablepress-{$table_id}_filter input' ).val() + ' ' + $( this ).data( 'filterterm' )

    However, after 15+ tries we couldn’t make it.

    I am sure there are many users who would like the filter/remove filter feature. When you have time, I am in no hurry, could you please take a look at this?

    Best regards

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    something like this should work:

    var filter_term = '';
    if ( '#reset#' !== $( this ).data( 'filterterm' ) ) {
      filter_term = $( '#tablepress-{$table_id}_filter input' ).val() + ' ' + $( this ).data( 'filterterm' );
    }
    {$name}.search( filter_term ).draw();

    Then, you could use a button like

    <button class="table-123-filter" data-filterterm="#reset#">Reset</button>

    to reset the search.

    Regards,
    Tobias

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Multiple filters simultaneously’ is closed to new replies.