Okay
  Public Ticket #3504641
WPDatatables
Closed

Comments

  • Dan Dewey started the conversation

    In a similar way to editing someones own data limitation I'd like to know if there is a way I can filter the data by a custom user field.


    As an example

    My wordpress users have a company field, so we know which company each user works for.


    In an SQL table we have a column for company name.


    Can we set a restriction or filter in place so each user only sees there own companies data.


    If user1,user2 and user 4 are working for Company A, they only need to see Company A data

    Where as user3 works for company B they only need to see Company B data


    If 

  •  1,708
    Miloš replied




    Hi Dan,

    Firstly, I would like to sincerely apologize for the delayed response as we have been experiencing an unusually high number of tickets. I am sorry that it has taken longer than usual to respond to your concern and your patience is highly appreciated.

    -

    At the moment, we do not have any dynamic Placeholder which can be used to look up the "User Role" for filtering or editing, so there is no easy built-in solution to filter the data like this as for your desired use-case.

    As you know, for User ID, we do have a placeholder so our developers created that "limit what each user can see and edit" based on the unique User ID.

    I will show you a custom SQL Query example with how you could try to filter a Table by User Role.

    So you could use any Membership Plugin/ or "User role editor" to add Custom User Roles.

    Then you can group your users, for everyone that works for Company A - to those users add additional Role for "Company A"  , and so on.

    Please be advised that this is just a custom example of using default WP user Roles, for your use-case you would need to modify our example.

    Our Support does not cover writing or debugging Custom Queriers for our Users, but i hope it helps.


    If I have this table:

    5458776907.png

    This is a manual table which has manually entered IDs from wp_users and roles from wp_usermeta:

    7855603551.png
    6462766399.png
    7686895681.png

    So, then I go to create an SQL query based table which will display entries based on user roles using this query:

    SELECT  new_table.id AS ID,      
      new_table.role AS Role,     
       new_table.product AS Product,  
          new_table.amount AS Amount
    FROM wp_wpdatatable_6 AS new_table
    JOIN wp_usermeta AS new_table_1
    ON new_table_1.user_id = %CURRENT_USER_ID%
    AND new_table_1.meta_value LIKE CONCAT('%', new_table.role, '%')
    

    When I'm logged in with user ID = 1, I see this:

    9999185249.png

    When I'm logged in with user ID = 4, I see the same thing. And when I'm logged in as one of the subscribers, I can only see the rows where role = subscriber:

    2907856651.png

    The only difference is that as subscriber I don't have access to back-end, so this confirms it is working on both front and back.

    So, we're only left with hiding unnecessary columns, adding names, and so on.

    Hope this 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

  •  1,708
    Miloš replied

    Hi Dan,

    Sorry, i just forgot to add, if you wish to see a Placeholder added in the future that can look up for the "Currently Logged in User Role" to be able to use it for filtering, you can make a development suggestion and our devs will do their best to work on it as soon as possible.

    -

    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.

    You can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;

    and our newsletter, so you're informed about new features, bug fixes, freebies, etc.

    -

    Otherwise, for the time being you can only try with a custom SQL Query solution and using Custom User Roles as described.

    Thank you.

    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