First try of "Join Tables Example" with Editor -> DataTables warning: table id=users - Ajax error.

First try of "Join Tables Example" with Editor -> DataTables warning: table id=users - Ajax error.

olivervogtolivervogt Posts: 6Questions: 2Answers: 0

Hi - I have just generated (or actually not) my first "Join Tables" example page on my own test server with the editor but got an Ajax error message. I am not sure if this is due to the code or another server setting. Here is what I did...

  1. Generate a simple set of 'Editor data tables' zipped files with the Generator online (same table structure as the online "join tables" example online) - there are actually two sets of zipped files - one for each table: 1x users + 1x sites
  2. Download and explore all files, in particular, the following three: myTableName.html -> myTableName.js -> myTableName.php
  3. Unzip both sets of "Generator Files" into one directory + edit MySQL credentials in config.php + upload to my webserver and run the code
  4. ...so far so good... The Editor works well!
  5. Next ... modify the autogenerated code based on the online example https://editor.datatables.net/examples/simple/join.html

- do nothing with the root directory file myTableName.html
- as referenced in the HTML file above in directory js/myTableName.js - copy paste js code from online example
- as references in the JS file above in directory php/myTableName.php - copy-paste php code from online example
- as references in the PHP file above in directory sql/myTableName.sql - do nothing ... code to run only once...

The only changes are:
- different table name "dtusers" instead of "users" in the original online example
- modified the "sites" column in the "users" table to be "int" in phpmyadmin (this was "text" when auto generated)
- here are all the files: https://drive.google.com/file/d/1BaUxtupJuvIZLPKNnN_1YuVQaYm_0JUk/view?usp=sharing

The error message is as follows:
DataTables warning: table id=dtusers - Ajax error. For more information about this error, please see http://datatables.net/tn/7

What would be the issue here?

Thanks,
Oliver

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Answer ✓

    Did you follow the diagnostic steps in the link provided in the error message? That would be the place to start debugging.

  • olivervogtolivervogt Posts: 6Questions: 2Answers: 0

    thanks for the quick reply - doh!

    there are two references to the file "myTableName.php" in file "myTableName.js" - one was changed and one was not... all good now ;-)

    Thanks,
    Oliver

  • olivervogtolivervogt Posts: 6Questions: 2Answers: 0

    Hello, one other point from this... let's say I add a column 'description' to the sites table. Is there a way to only display the column 'description' on the joined user table?

    e.g. display two additional columns (1) site name (2) site description.

    Thanks,
    Oliver

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Sure - if you consider this example it only shows the site name column from the joined table, not anything else. You just need to include only the columns that you need in the fields array (assuming you are using our PHP libraries).

    Allan

  • olivervogtolivervogt Posts: 6Questions: 2Answers: 0

    Thanks, both. All works well. For completeness - here is the PHP snippet if you like to display another column from a joined table e.g. notes related to the site in this case ...

       Field::inst( 'users.site' )
            ->options( Options::inst()
                ->table( 'sites' )
                ->value( 'id' )
                ->label( 'name' )
            )
            ->validator( Validate::dbValues() ),
        Field::inst( 'sites.name' ),
        Field::inst( 'sites.notes' )
    )
    ->leftJoin( 'sites', 'sites.id', '=', 'users.site' )
    

    here is the js snippet:
    { data: "sites.name" },
    { data: "sites.notes" }

    Thanks,
    Oliver

Sign In or Register to comment.