DataTables Editor - joined tables example

DataTables Editor - joined tables example

estudiosestudios Posts: 52Questions: 0Answers: 0
edited June 2013 in Editor
Can you provide the name of the table and the fields in each table. I am confused with the sintaxis trying to understand
Thanks a lot

Replies

  • estudiosestudios Posts: 52Questions: 0Answers: 0
    Alan, I gonna write a few more to clarify my questions...

    I want to get the field named "razsoc" from the table named "empresas".
    I have, in the table named "contactos", a field named "idempresa" and I have, in the table named "empresas", the fields named "id" and other named "razsoc"

    What is wrong

    My php code:
    Editor::inst( $db, 'contactos' )
    ->fields(
    Field::inst( 'nombre' ),
    Field::inst( 'pais' ),
    Field::inst( 'direccion' ),
    Field::inst( 'email' ),
    Field::inst( 'tel1' ),
    Field::inst( 'iva' ),
    Field::inst( 'cuit' ),
    Field::inst( 'notas' )
    )
    ->join(
    Join::inst( 'empresas', 'object' )
    ->join( 'idempresa', 'id' )
    ->fields( Field::inst( 'razsoc' ))
    )

    ->process( $_POST )
    ->json();

    And my js code:
    $('#EEcontactos').dataTable( {
    "sDom": "Tfrtip",
    "sAjaxSource": "php/_table.EEcontactos.php",
    "aoColumns": [
    {"mData": "nombre"},
    {"mData": "pais"},
    {"mData": "email"},
    {"mData": "tel1"},
    {"mData": "empresas.razsoc",
    "sDefaultContent": ""}

    ],
    "oTableTools": {
    "sRowSelect": "single",
    "aButtons": [
    { "sExtends": "editor_create", "editor": editor },
    { "sExtends": "editor_edit", "editor": editor },
    { "sExtends": "editor_remove", "editor": editor }
    ]
    },
    "fnInitComplete": function ( settings, json ) {
    // Set the allowed values based on
    // what is available in the database
    editor.field('idempresa').update( json.empresas );
    }

    } );
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    edited June 2013
    That almost looks okay to me.

    I think you need an extra little bit of code to get whatever it is you want into `json.empresas` (possibly something like in this example http://editor.datatables.net/release/DataTables/extras/Editor/examples/join.html ), but the basic structure looks fine other than that. Are you getting an error somewhere?

    Allan
  • estudiosestudios Posts: 52Questions: 0Answers: 0
    Thanks a lot.

    yes I got an error JSON not be parsed...etc and if I delete the following code no error but no data from the "empresas" table

    ->join(
    Join::inst( 'empresas', 'object' )
    ->join( 'idempresa', 'id' )
    ->fields( Field::inst( 'razsoc' ))
    )

    again thanks a lot
  • estudiosestudios Posts: 52Questions: 0Answers: 0
    few more steps

    It seems that I have diferent tables structure and I am using join in the wrong way

    My tables are
    1) CREATE TABLE `contactos` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `idempresa` int(11) DEFAULT NULL,
    `nombre` char(30) DEFAULT NULL,
    PRIMARY KEY (`id`))
    2) CREATE TABLE `empresas` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `razsoc` char(100) CHARACTER SET latin1 DEFAULT NULL,
    PRIMARY KEY (`id`))

    field "idempresa" in table "contactos" is relationated with field "id" in table "empresas"

    I want to see a list with "nombre" from table "contactos" and "razsoc" from table "empresas"

    I would appreciate very much your help

    thanks a lot
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    > yes I got an error JSON not be parsed...etc

    Okay - that's quite important. What is actually being returned from the server? Likely there is an error message shown which will indicate what the problem is.

    Thanks,
    Allan
  • estudiosestudios Posts: 52Questions: 0Answers: 0
    Alan, the error is: DataTables warning (table id=EEcontactos): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.

    I am still can not join the tables. Should I pay 1 hour support to get more help?

    Thanks a lot
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    We need to know what the JSON return from the server is. The error message is telling you that its not valid JSON, but we need to know what it actually - likely it will contain an error message which will hopefully lead us to a solution. You can find out what is actually being returned by using Firebug or Inspector or similar.

    You are most welcome to pick up DataTables support :-). It would allow me to prioritise your questions and respond as quickly as possible.

    Allan
  • estudiosestudios Posts: 52Questions: 0Answers: 0
    I got the error, solve one and got another. I do not have join.php file in this path. Do you know why?

    Warning: require(/var/www/consultas/php/lib/Editor/Join.php) [function.require]: failed to open stream: No such file or directory in /var/www/consultas/php/lib/Bootstrap.php on line 48

    Fatal error: require() [function.require]: Failed opening required '/var/www/consultas/php/lib/Editor/Join.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/consultas/php/lib/Bootstrap.php on line 48

    I file the request for support to my administrative manager. As soon as I get the approval I gonna load the support fee.

    Thanks
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Have you downloaded the full Editor package from https://editor.datatables.net/download ? The trial version of Editor doesn't include the Join.php file, but the licensed download package (which you should be able to download since you have a license :-) ) does include that file.

    Regards,
    Allan
  • estudiosestudios Posts: 52Questions: 0Answers: 0
    almost done.

    The table looks good and the editor Windows also.B

    BUT if I change the type TEXT for SELECT, no data is avalilable for selection
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Have you supplied it with data using the `ipOpts` option? Example: http://editor.datatables.net/release/DataTables/extras/Editor/examples/fieldTypes.html

    Allan
This discussion has been closed.