Parent Child Files.
Parent Child Files.
Riddley_Walker
Posts: 15Questions: 2Answers: 0
Is there any chance anyone has a working set of files or even a fiddle that shows a working parent child set of 2 tables (or even the mixed in version shown in the 2019 parent-child blog post - https://datatables.net/blog/2019-01-11). I can't get it to work and am just about ready after trying for over 20 hours to move on.
This discussion has been closed.
Replies
Hi @Riddley_Walker ,
That example you linked to is using Editor - is that what you're after? If you just want view-only tables, then here's another example on this thread .
Alternatively, link to your page or create an example and we can take a look!
Cheers,
Colin
Thanks, yes...I will need editor.
First I tried just making sure I could link up to the databases. I created a page with two tables with editing. It works fine: http://74.124.214.194/~themoviechef/TwoTables.html.
Things seem to break when I work on the .js files. I also wonder if the early article on master client is still current in terms of methodology.
I think I posted everything earlier as a question, but it doesn't seem to be showing up. I will go through it again this evening and post here. I would really appreciate any help!
One problem is that you are using the same variables (editor, table) for both site and user Editor and Datatable. You will want different variables. For example, see the change in variables for the user table:
Kevin
Oh dear. It looks like my long response to your email may have gotten swallowed by the ether. I'm going to redo it. Ugh. I will break it into several replies in case there is a length limit.
i am lost. my posts don't seem to be showing up if they have code even when i use the triple black ticks. Maybe you're seeing them behind the scenes.
OK guys. First, thank you.
It seems like everything I'm doing is making it worse, so I'm going to post what I have so far. But, let me start w/a comment and a question.
Just to recap: the working version of the program with two non-linked tables is at http://74.124.214.194/~themoviechef/TwoTables.html
The Non-working linked-table version is here: http://74.124.214.194/~themoviechef/TwoTables2.html
Kevin, in response to your letter, in my non-working linked version, the editors are, I believe, named differently.
The only thing I'm wondering about is that I'm not seeing a call to jquery, even though the original model I used (from generator) did say to include it. Maybe it is somewhere internally called, but I'm not sure. That said, the unlinked two table version seems to work, so I don't think that is the problem.
Here are the non-working linked-table files. First, the HTML file TwoTables2.html:
Next the js file. Note, I've tried a few versions of this, but ultimately copied this out of the blog post, and modified the location and names of the php files:
Then I have the .php file table.sites2.php
and table.users2.php
```
<?php
/*
* Editor server script for DB table users
* Created by http://editor.datatables.net/generator
*/
// DataTables PHP library and database connection
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
// The following statement can be removed after the first run (i.e. the database
// table has been created). It is a good idea to do this to help improve
// performance.
$db->sql( "CREATE TABLE IF NOT EXISTS
users
(id
int(10) NOT NULL auto_increment,name
varchar(255),PRIMARY KEY(
id
));" );
// Build our Editor instance and process the data coming from _POST
<?php > ``` Thank you for your input and time. ?>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();
}
First, thanks for your help. I seem to have now broken the non-linked version, too. I don't really care about that one at the moment though. I now feel like a dog chasing its tail.
Here is the HTML File:
The .js file was largely taken from the internals of the blog post, just modifying the paths and file names
I will finish up the php files in the next post.
OK guys. First, thank you.
It seems like everything I'm doing is making it worse, so I'm going to post what I have so far. But, let me start w/a comment and a question.
Just to recap: the working version of the program with two non-linked tables is at http://74.124.214.194/~themoviechef/TwoTables.html
The Non-working linked-table version is here: http://74.124.214.194/~themoviechef/TwoTables2.html
Kevin, in response to your letter, in my non-working linked version, the editors are, I believe, named differently.
The only thing I'm wondering about is that I'm not seeing a call to jquery, even though the original model I used (from generator) did say to include it. Maybe it is somewhere internally called, but I'm not sure. That said, the unlinked two table version seems to work, so I don't think that is the problem.
Here are the non-working linked-table files. First, the HTML file TwoTables2.html:
Next the js file. Note, I've tried a few versions of this, but ultimately copied this out of the blog post, and modified the location and names of the php files:
Then I have the .php file table.sites2.php
and table.users2.php
```
<?php
/*
* Editor server script for DB table users
* Created by http://editor.datatables.net/generator
*/
// DataTables PHP library and database connection
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
// The following statement can be removed after the first run (i.e. the database
// table has been created). It is a good idea to do this to help improve
// performance.
$db->sql( "CREATE TABLE IF NOT EXISTS
users
(id
int(10) NOT NULL auto_increment,name
varchar(255),PRIMARY KEY(
id
));" );
// Build our Editor instance and process the data coming from _POST
<?php > ``` Thank you for your input and time. ?>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();
}
First, thanks for your help. I seem to have now broken the non-linked version, too. I don't really care about that one at the moment though. I now feel like a dog chasing its tail.
Here is the HTML File:
The .js file was largely taken from the internals of the blog post, just modifying the paths and file names
I will finish up the php files in the next post.
Hi @Riddley_Walker ,
Sorry, your replies got caught in the spam filter for some reason - I've released them now and will take a nose in a tick.
Cheers,
Colin
Is showing a Javascript error. That appears to be because the HTML defines only one column, but the Javascript is defining two for the
#sites
table. If you add another column to the HTML that should at least initialise.Likewise with the
users
table you have one column in the HTML but four defined in the Javascript.Allan