Need a working example of how to create an all-in-one parent/child editing view/form.
Need a working example of how to create an all-in-one parent/child editing view/form.
I have a number of forms that are inter-related in a parent/child method. As is I have them set up so that I visit the parent form, categories.php, for example then inline I add a render link in one of the columns that passes the id to the child and opens the child form (separate page).
It would be many times easier to visit the categories page, click/select a category row and load the child articles in a second table on the same page. Click to a different category and it loads its child articles. I found this post:
https://datatables.net/blog/2016-03-25
It meets the goal and I tried to create the forms using 2 tables articles and article_categories but found that the post is incomplete towards the ends and I could not glue it together.
The link to my demo: https://www.dottedi.xyz/bin/article-categories.php
In the post there is a reference to the following code but it does not say where it gets added:
table.row( { selected: true } ).data();
When I got to this next item and added this code in the child table that would break the page article categories page from loading data. It sticks at "loading" but never loads:
->join(
Mjoin::inst( 'users' )
->link( 'sites.id', 'users.site' )
->fields(
Field::inst( 'id' )
)
)
And yes, I updated the fields to the correct table names and field names. With that disabled I updated the server side php file adding the if/else code described here but replacing it with my table name/fields:
if ( ! isset($_POST['site']) || ! is_numeric($_POST['site']) ) {
echo json_encode( [ "data" => [] ] );
}
else {
Editor::inst( $db, 'users' )
->field(
Field::inst( 'users.first_name' ),
Field::inst( 'users.last_name' ),
Field::inst( 'users.phone' ),
Field::inst( 'users.site' )
->options( 'sites', 'id', 'name' )
->validator( 'Validate::dbValues' ),
Field::inst( 'sites.name' )
)
->leftJoin( 'sites', 'sites.id', '=', 'users.site' )
->where( 'site', $_POST['site'] )
->process($_POST)
->json();
}
That caused the page to break. I also don't see how/where you bring the child table onto the page. The general problem is that the solution is incomplete and doesn't provide adequate help regarding where some of the code parts belong.
I made .txt copies of my php files. To see them visit:
https://www.dottedi.xyz/bin/dt/article-categories.php.txt
https://www.dottedi.xyz/bin/dt/articles.php.txt
The php/controller files:
https://www.dottedi.xyz/bin/controllers/article-categories.php.txt
https://www.dottedi.xyz/bin/controllers/articles.php.txt
I could add the text directly into this post but it would get very long. If it helps say so.
Thank you
Answers
Our records appear out of date, we're not seeing a license for Editor under your account. Was Editor licensed to another user? If so, please could you PM me the details.
Colin
That line is meant to be an example of how you can get information about the selected row. The actual use of the concept introduced there is in the block just below it (and the one after that):
The idea there is that you get the
id
from the currently selected row and send that to the Editor / DataTable PHP scripts for the child table so they know what group they should be working on.Allan
This is that example in full and no explanation text, which might also be useful for you to refer to.
Allan
I saw that earlier but thought it was incomplete, so kept looking. Anyway I copies the article-categories.php page to multi-level.php (just a name to differentiate) and then copied in and modified the code from the new example. The code for the new multi-level.php file:
You can see the result at:
https://www.dottedi.xyz/bin/multi-level.php
Not there yet. My 2 tables are article_categories and articles. I substituted in the name changes where I understood.
You can view the php files at:
https://www.dottedi.xyz/bin/controllers/articles.php.txt
https://www.dottedi.xyz/bin/controllers/multi-level.php.txt
Hi,
Thanks for the link. I'm getting a Javascript syntax error in
bin/multi-level.php
line 101 (when rendered):Should be:
Allan
I found and updated that on line 72 yet the page is still not rendering.
Please make sure to fix all your errors. You are now getting this error:
Kevin