Okay
  Public Ticket #3392766
Change Advanced Filter value programmatically
Closed

Comments

  • TonyF started the conversation

    Is it possible to dynamically change an Advanced Filter value programmatically?  If so, can you provide some example code?  I know I can achieve this using placeholder variables but these variables seem to be shared by all users and I would like the filtering to be dynamically set based on the user.

  •  1,708
    Miloš replied

    Hi, TonyF.

    I am not sure i understood your use-case.

    If you need to have a dynamic filter that looks for the currently logged user's informations,

    we have these placeholders available :

    Currently logged user ID, 

     Login Username, 

    Email , 

    First Name,

     Last Name.

    6720018943.png

    There are two ways how you can use our "currently logged users" placeholders,

    via SQL Query with "WHERE" Statement,

    and with a predefined column filter.

    I will share my example for using the current user's Email for filtering the table.

    -

    You can use our dynamic placeholder %CURRENT_USER_EMAIL% for this purpose.

    There are two ways how you can do this.

    If you have an SQL Query based table, just add this to your Query.

    Let's say if your SQL Query was simple like this :

    "SELECT * FROM TableName"

    Then, just add this WHERE statement to filter the table in your Email Column by current user Email :

    SELECT * FROM TableName
    WHERE email= '%CURRENT_USER_EMAIL%'

    and then this SQL table will only load rows for the currently logged user's Email.

    Just change the "TableName" with your table name, and "email" with your origin Header name of the email column.

    -

    Or, if you don't use SQL Tables, you can also use predefined filter value in your email column, 

    go in the columns Filtering settings, set it as Text type, add predefined filter value as this placeholder :

    5126983293.png

    This is how my test table looks, i got a few emails in this column.

    6485412620.png

    Now it will just filter by my currently logged email.

    6772485013.png

    Let me know if that helps.



    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • TonyF replied

    I am using an SQL query to generate the table.  I currently have an advanced filter configured to use the %VAR3% placeholder as the advanced filter predefined value.

    7530743754.png


    I programmatically set var3 on a page load using and sql query like: "UPDATE wp_wpdatatables SET var3 = %s WHERE id = 10".  This does the default filtering I want and still allows the user to change the advanced filter and use the advanced filters clear button.  However, if multiple users are accessing the table, var3 will be changed inappropriately for all but the latest user.

    What I'm really looking for is unique persistence of the advanced filter predefined value for each user based on their last used advanced filter value.

    Example:

    User1 sets the advanced filter to a value of 50, uses the table and logs out.

    User2 sets the advanced filter to a value of 100, uses the table and logs out.

    When User1 logs in later, I'd like the advanced filter to be preset to the last used value of 50 and when User2 logs in later, I'd like the advanced filter to be preset to the last used value of 100.  Is this possible?

  •  2,513
    Aleksandar replied

    Hello Tony.

    I'm sorry to disappoint you, but unfortunately, something like this is not yet possible.

    wpDataTables can't recognize a session like that. We'll forward it to our developers, as an idea for the future, but for the time being there's no way something like this can be achieved.

    At this time, we don't have any built-in solution to achieve this, but you can suggest it to our developers - they will do their best to make a solution in the future.

    Please feel free to search on our suggestions page, to see if someone may be already suggested this feature. If you can't see it, feel free to add your suggestion there,  and as more people vote, the feature will move higher on the priority list.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables