Okay
  Public Ticket #3589200
master detail
Closed

Comments

  • Fidel started the conversation

    Let's say we have a employees and department relationship. One department has many employees.
    I want to have in the initial datatable show only the departments (master), so, when the initial grid is shown it will show one row per department, when you click the row, it will show a pop up window with all employees for that department.

    How can I accomplish that?

  •  1,846
    Miloš replied

    Hi Fidel,

    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.


    If you use our built-in Foreign Key Relation, for example, with a Foreign Key Column made in this way through our Plugin, it can only be a "one to one" relation;

    it can not create a "one to many" relation.


    If you wish to see a  "one to many" relation possible in our Foreign Key Column Feature, you can make a development suggestion for the future, but I can't say a realistic ETA if or when that might become 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.



    2. But, let's ty alternate workarounds to 'present the data like that'.

     If you create, let's say, one  Manual Table which stores all the Departments;

    and if you have another Table that holds all the possible "employees";


    Then, you can create a third, SQL Query Based Table which is going to call only the data you need to be 'presented' and you can add a Foreign Key Column in this Table to call the "employee values".


    When you make an SQL Query table from a Manual Table;

    First go to the Manual table, check under the Editing options, for the MySQL Table Name, then call this table as :

    SELECT * FROM TableName.

    ( The SQL Table will be editable, and any rows you edit on it - will be reflected in the source Manual Table)


    Then, you can make a Foreign Key Column - name it anything, like "employee name" for example, to pull all the possible Employee name values there.


    Please check our explanation/guide with example above in the hyperlink i sent how our Foreign Key Column feature works to see how to make the relation to pull values from the foreign Table "Employees" in this "Departments" Table.


    In short, at first you would make an integer Column in this Manual Table - so it gets saved in the SQL source Table as integer;

    then change to String Type - and make your relation.


    Then, as we mentioned, you can't do a "one to many relation" in our Foreign Key Column, but you will be able to add multiple rows, so you will initially have some employees with 'multiple rows' if they belong to multiple departments.


    But, in the end, you can use our "Row Grouping" Feature to present the data as you need it.

    I will show you an example with our Dummy SQL "Employees" Table.

    You can try this feature out on our main Demo Sandbox, here. ( Let's say on Table #1 "dummy_employees")


    If we wish to Group rows on this column by the Employee Position.

    2412104361.png

    This is an SQL Table, so we have to disable server-side processing in order to get the "Row Grouping" feature available.

    As you can see on this Documentation,   Row grouping feature is only available for non-server-side tables.

    ( Which basically means all tables besides Manual or Simple Tables, and for SQL Tables just disable server-side toggle)

    8588078393.png

    Back to the example.

    So now, we go in this Position column settings, and enable the Row Grouping.

    7500473282.png

     And, it will look like this :

    3149605193.png


    So, in your scenario, you could do this on your "Department name" Column, and it is going to look like that;

    one row per each Department, and listing out all the employees who work for that department in the rows beneath;

    then the next Department row grouped, and so on...


    Let me know if that helps.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    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