Okay
  Public Ticket #3375912
Creating Editable Tables in WordPress where users can see and edit only their own data
Closed

Comments

  • GEORGE started the conversation

    Dear Sir/ Madam,

    I would like to ask you if with wp datatables I can build the below idea for a client. I have a project for 50 DRIVING SCHOOLS that means 50 users.

    Please find my attachment explaining what I need to do for a client.

    Thank you in advance.

    Attached files:  Creating Editable Tables in WordPress where users can see and edit only their own data.pdf

  •  1,819
    Miloš replied


    Hi, George.

    Sorry for the delayed response time.

    -

    I am not sure i fully understood all aspects of your use-case, how the table should be constructed in terms of which columns and rows the logged users should see and be able to edit.

    1. For example, if you simply wish to use our built-in option "users can see and edit only their own data ",

    this is based on a logic where you add a "user ID" column, which has to be an integer type.

    When you activate the option in Editing to limit the rows a logged user and see or edit,

    then at first this user would see an empty table ( unless if you manually already populate the rows, to have the appropriate user ID in each user ID column's row for them - then it would only show them the rows which are associated with their user ID from "wp_users" table)

    You can check more details on how this works in the hyperlink from Documentation above.

    -

    2. Restricting access to a table for logged users only :

    Our plugin does not have any option for limiting access to see a table;

    but you can easily do that with a Membership Plugin.

    And with a "User Role Editor" you can also add custom user roles - if needed,

    then you can have, let's say Page 1 where you set a Shortcode for Table #1 that only user logged with role of "Level1" can see, for others the page would be blocked;

    and on Page 2 you can set another Table that is just for user Role "Level 2" and so on.


    3. 

    I want them to be able to select from the columns the number (float or manually
    enter the number) of students they have for each category and save it.

    In your example, i see you have this column "School Names".

    I presume that if a user is from "Driving School 1",  he should only see that row?

    Then if another user from "Driving School 2", he should only see this row?

    7157079680.png

    If you plan to have only one user for each School, then you can just change the approach for that Column of "School Names", you can remove this column and instead just add a hidden Integer user ID column to this table, 

    and pick it to be the "userID" column for "users see and edit own rows".

    For Admin in the back-end, you can enable the Admin to see all rows.

    7209310784.png

    Now, in this table, not even Admin can edit the rows he did not make.

    If you need Admin to be able to edit all rows,

    then you can make two table workaround.


    For example, you can have one main/master Manual table which will store all the data in the database.

    Then, you can check this table's MySQL Table name from the Editing tab in the back-end table settings,

    and you will be able to make multiple SQL tables that pulls data from the same "master table",

    and any editing you do on all these other SQL tables are going to be stored in the same table in the database,

    This will be my example table :

    3791094982.png

    Now, to make a new SQL Table from it,

    first, check in Editing Tab/MySQL table name for editing:

    6795720227.png

    in my example, the Manual table name is wp_wpdatatable_39,

    so i make a new SQL table that will pull data from it;

    and we can choose all columns like :

    SELECT * FROM Table_Name

    or just specific columns;

    we can also have completely different settings/filtering/sorting and limitations for front-end users on each table;

    and you can make multiple SQL Query tables that pull the same data from the "main table".

    SELECT  column_name1,
            column_name2,
            column_name3
    FROM table_name

    -

    In this example, if i want to limit to only show the "Company" column, and i will leave wdt_ID ( because we got to have row ID)  and userid ( if we want userID for limiting rows per currently logged user ID),

    when i hide those columns in the end, the front-end user will only see the "company" column.

    SELECT  wdt_ID,     
       userid,     
      company     
      FROM wp_wpdatatable_39
    4596672496.png

    Later, you can make another SQL Table that will show some other columns, have other filters and so on ( depending on what you need to achieve)...

    You can see my Video example here https://watch.screencastify.com/v/jOXrsJ9jaspWG5m3VqZH

    -


    For the "Results", you can use our SUM calculation, that will just add a Total row at the bottom, and you can rename the label for the SUM in main plugin settings.

    This SUM is going to dynamically change as you filter the table/it calculates on the fly only for visible rows.


    And i just wanted to point out that you can try wpDataTables before purchasing

     on our sandbox Demo sites ( you can find links for the main plugin Demo,  

    as well as add-on Demos, in my signature),

    and there is a 15-day money-back guarantee period, 

    so if you purchase the plugin, you can safely fully test it out, and if it doesn't fit your needs you can request and receive a refund in that period. ( same goes for all plugins and add-ons)

    Let me know if you have any additional questions. smile.png



    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

  • GEORGE replied

    Dear Milos, 

    Thank you very much for your guidance and instructions!! I've checked your options and I found most of the answers to my queries!! One last main thing to figure is about the users?? I can not understand how to connect the users with the integer id column??? Do I have to create simple users to wordpress section??? and then it will automatically generate and user number or name??? how it works????


    Thank in advance,


    Kind regargs,

    George

  •  1,819
    Miloš replied

    Hi, George.

    You're welcome, i am happy to help.

    Yes, in regards to using our built-in option "users can see and edit only their own data ",

    this can only be used on SQL based tables, which are Manual Tables, or SQL Query based tables.

    You can also make a new Manual Table by importing data from CSV/Excel/Google Sheets.

    -

    The logic behind our feature that checks for the User ID works in a way that first you need to have some WordPress registered users on your site.

    For each new user, WordPress adds their user ID in this table in your Database, named "wp_users".

    You can find it with your PHPMyAdmin, for example.

    And the wp_  is the default WP DB table prefix, on your site it can be different, so something like "yourPrefix_users".

    Now, our plugin looks to check which user is currently logged in,

    and if you open any Manual or SQL Table, you can check in the Placeholders Tab of table settings,

    and it shows your User ID.

    8764442558.png

    You can also see a tooltip, if you go in an editable table, under Editing Tab, when you enable the "Users see and edit only own data",  check this tooltip when you hover the mouse over "User ID column".

    8013012588.png

    Here you have to select which column is used for the "userID" field.

    It references the user ID from wp_users in your Database, and checks with the currently logged user ID.

    If they match, then it shows all their rows.

    If they try a new row - this new row automatically populates with their user ID, in your chosen user ID field of the table.

    That field has to be integer in the database.

    Let us know if that makes sense.

    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