Generated Configuration

Generated Configuration

FroopleDesignFroopleDesign Posts: 21Questions: 3Answers: 0
edited August 2023 in Free community support

Good afternoon,
I have some questions in regards to setting up my datatables. I'm in the process of converting my PHP Core datatables to the editor datatables. I've managed to set up my nested editing, the data is properly updating my mysql, but i have two main concerns.

First, the stylesheets and javascript generated by the editor generator package seem to be invalid links.

    `<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jqc-1.12.4/moment-2.29.4/jszip-3.10.1/pdfmake-0.2.7/dt-1.13.6/b-2.4.1/b-colvis-2.4.1/b-html5-2.4.1/b-print-2.4.1/cr-1.7.0/date-1.5.1/fc-4.3.0/fh-3.4.0/r-2.5.0/sc-2.2.0/sb-1.5.0/sl-1.7.0/datatables.min.css">

<script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/v/dt/jqc-1.12.4/moment-2.29.4/jszip-3.10.1/pdfmake-0.2.7/dt-1.13.6/b-2.4.1/b-colvis-2.4.1/b-html5-2.4.1/b-print-2.4.1/cr-1.7.0/date-1.5.1/fc-4.3.0/fh-3.4.0/r-2.5.0/sc-2.2.0/sb-1.5.0/sl-1.7.0/datatables.min.js"></script>`

Second , i'm having what seems to be a client side error when editing/creating items in the datatable.
My js: https://codeshare.io/Rb9rBV

Third, can i assume that if i generated the files using datatables generator, the license key is included, where can i find the license key to ensure its properly configured?

`<b>Warning</b>
:  Undefined array key 0 in <b>/.../...public_html/.../.../.../php/lib/Editor/Join.php</b>
on line <b>797</b>`

For the first issue, im considering obtaining the individual links to replace the merged link.
As for the second issue if anyone could point me in the right direction, i'd be gratefull.

`<?php

/*
 * Editor server script for DB table userinfo
 * 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;



// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'userinfo', 'userid' )
    ->fields(
     Field::inst( 'userid' ),
     Field::inst( 'username' ),
     Field::inst( 'platform' ),
     Field::inst( 'reach' ),
     Field::inst( 'category' ),
     Field::inst( 'registeredon' ),
     Field::inst( 'icon_id' )
    )
    
           ->join(
        Mjoin::inst( 'contactInfo' )
            ->link( 'userinfo.userid', 'contactInfo.userid' )
            ->fields(
                 Field::inst( 'id' ),
                Field::inst( 'userid' ),
                Field::inst( 'phone' ),
                Field::inst( 'email' )
            )
    )
    
    
           ->join(
        Mjoin::inst( 'iconData' )
            ->link( 'userinfo.icon_id', 'iconData.platform_id' )
            ->fields(
                Field::inst( 'platform_id' ),
                Field::inst( 'url_prefix' ),
                Field::inst( 'icon_image_url' )
            )
    )
                  
    
    ->process( $_POST )
    ->json();
`
`// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'contactInfo', 'id' )
->fields(
     Field::inst( 'contactInfo.id' ),
                Field::inst( 'contactInfo.userid' ),

                Field::inst( 'contactInfo.phone' )
                 ->validator( Validate::notEmpty() )
                 ->validator( Validate::minMaxLen( 8, 15 ) ),

                Field::inst( 'contactInfo.email' )
                 ->validator( Validate::email( ValidateOptions::inst()
                 ->message( 'Please enter an e-mail address' )  
                 ) )




            )


             ->join(
        Mjoin::inst( 'userinfo' )
           ->link( 'userinfo.userid', 'contactInfo.userid' )
            ->fields(
                    Field::inst( 'userid' )
    )
        )

               // Check if the "userid" key exists in the $_POST array before using it
    ->where(function ($q) {
        if (isset($_POST['userid'])) {
            $q->where('userid', $_POST['userid']);
        }
    })
    ->process( $_POST )
    ->json();`
`{
    "data": [
        {
            "DT_RowId": "row_65",
            "userid": 65,
            "username": "test",
            "platform": "Instagram",
            "reach": "1k",
            "category": "Food",
            "registeredon": "2023-06-14 07:08:15",
            "icon_id": 1,
            "contactInfo": [{ "id": 3, "userid": 65, "phone": "+965 ttttt", "email": "test@test.com" }],
            "iconData": [{ "platform_id": 1, "url_prefix": "https://instagram.com/", "icon_image_url": "fa-brands fa-instagram" }]
        },
    
    ],
    "options": [],
    "files": []
}

contactinfo:
{ "data": [{ "DT_RowId": "row_3", "contactInfo": { "id": 3, "userid": 65, "phone": "+965 ttttt", "email": "test@test.com" }, "userinfo": [{ "userid": 65 }] }], "options": [], "files": [] }
> 
<br />
<b>Warning</b>
: Undefined array key 0 in <b>/.../.../public_html/.../.../php/lib/Editor/Join.php</b> on line <b>797</b> <br />
{"data":[{"DT_RowId":"row_65","userid":65,"username":"testt","platform":"Instagram","reach":"1k","category":"Food","registeredon":"2023-06-14 07:08:15","icon_id":1,"contactInfo":[{"id":3,"userid":65,"phone":"+965
ttttt","email":"test@test.com"}],"iconData":[{"platform_id":1,"url_prefix":"https:\/\/instagram.com\/","icon_image_url":"fa-brands fa-instagram"}]}]}
`

This question has an accepted answers - jump to answer

Answers

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

    First, the stylesheets and javascript generated by the editor generator package seem to be invalid links.

    Sorry. It looks like Generator needs an update there. We no longer host pdfmake and a few other libraries, due to their size. pdfmake is massive, and it was cooking some serious bandwidth! Use the download builder to get the correct includes for your HTML.

    i'm having what seems to be a client side error when editing/creating items in the datatable.

    What's the error? Is there a JS error shown in the console, or something else?

    can i assume that if i generated the files using datatables generator, the license key is included, where can i find the license key to ensure its properly configured?

    There isn't a license key as such. Generator will either include the original Editor code if you have a license (which you do, so it will), or the obfuscated and time limited Editor code if you don't.

    Regards,
    Allan

  • FroopleDesignFroopleDesign Posts: 21Questions: 3Answers: 0

    Sorry. It looks like Generator needs an update there. We no longer host pdfmake and a few other libraries, due to their size. pdfmake is massive, and it was cooking some serious bandwidth! Use the download builder to get the correct includes for your HTML.

    Will do.

    What's the error? Is there a JS error shown in the console, or something else?

    Im not entirely sure yet. There are no errors in the console tab, however in the network tab ,my json response file has

    `<b>Warning</b>
    :  Undefined array key 0 in <b>../php/lib/Editor/Join.php</b>
    on line <b>797</b>`
    
    

    The response status is 200 ( success).

    so i believe its something to do with the client side json response. What's confusing me, is other than the error showing, Everything is working fine. The data is being created, it is being edited. However whenever i attempt to create or edit data, i get this error message.
    The error leads me to this page.
    https://datatables.net/manual/tech-notes/12

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

    Oh I see - sorry. it is once you add the Join code that you get an error, not the raw code from Generator (other than the include issue)?

    And this happens on submit of the data - the data load is okay?

    Can you show me the JSON that is loaded, and also the request parameters that are sent when submitting this form and this error happens?

    Thanks,
    Allan

  • FroopleDesignFroopleDesign Posts: 21Questions: 3Answers: 0
    edited August 2023

    Yes this happens after the join code is added and the data load seems to be ok. I apologize for not being clear. Everything is also being updated on the MYSQL server.

    https://codeshare.io/qPOYnX


    I could give you a direct link to the website if that helps, I just cant share the link in public.

    Thank you for all the effort you've put into my questions thus far allan, i greatly appreciate it.

  • FroopleDesignFroopleDesign Posts: 21Questions: 3Answers: 0

    My MYSQL table is as follows.

    userinfo

    contactInfo

    the userid in contactInfo is a foriegn key of the userid in userinfo. and the userid is autoincremented.

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

    If you are able to PM me a link to the page, that would be helpful. Click my forum user name and then "Send message".

    The data being submitted doesn't look quite complete - there should be a contactInfo-many-count parameter for example. I think seeing how the client-side is configured would be useful. Do you have the multiple: true option set for the datatable field for example?

    I presume it is the contactInfo field that is causing the issues and not the iconData one? I don't see any submitted data for that one.

    Allan

  • FroopleDesignFroopleDesign Posts: 21Questions: 3Answers: 0

    Yes its the contactInfo. I have this error on both my editor datatables. I will PM you the link.

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

    Super - thank you. I'm starting to put the pieces together now!

    Do you want each "user" to be able to have multiple "contactInfo"s assign to them, or just a single one?

    If a single one, then normally I would expect there to be a contactInfo reference in userinfo, rather than the other way around. Then you wouldn't use an Mjoin but just a standard leftJoin and update the id of the linked contactInfo in userinfo.

    The way the database is set up at the moment you would have an Editor instance for contactInfo and edit the user reference that it is linked to.

    You don't want Mjoin to operate on a table that contains other meta information (in this case phone and email as it will delete the row when doing an update and then insert a new one, but without that meta information (it doesn't attempt to do some kind of diff on the table).

    So if there is a single value that can be selected, don't use Mjoin. Use a left join.

    If however, you do need to select multiple contacts, I think you should add a "link" table between contactInfo and userinfo - so it can be many-to-many (or you can limit it to one-to-one if you really need). You'd also need to add multiple: true to the field's configuration.

    Hope that all makes sense - I think it will likely be a little tweak needed to your database schema, but what tweak will depend upon your requirements :)

    Allan

  • FroopleDesignFroopleDesign Posts: 21Questions: 3Answers: 0

    Do you want each "user" to be able to have multiple "contactInfo"s assign to them, or just a single one?

    The relationship between useinfo and contactInfo is 1-M ( One to many ). Each userinfo can have multiple contactInfo, the same applies to Events and EventLocations in the other table.

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

    Okay - awesome. No question in my mind then - add a link table (also known as a junction table). The delete action used by Mjoin is going to cause you headaches otherwise. Also add the multiple: true option to the DataTable field configuration.

    Allan

  • FroopleDesignFroopleDesign Posts: 21Questions: 3Answers: 0
    edited August 2023

    Decided on a temporary solution for now as everything is updating as it should at the moment. Changed line 797 in the join.php set. " $joinData[$i]" to "1".

    `       } else {
                for ($i = 0; $i < count($joinData); ++$i) {
                    $this->_validateFields($errors, $editor, $joinData[$i], $this->_name . '[].');
                }
            }
        }`
    
    

    to

    `   } else {
                for ($i = 0; $i < count($joinData); ++$i) {
                    $this->_validateFields($errors, $editor, 1, $this->_name . '[].');
                }
            }
        }`
    
    
    

    also added to the table php files.


    ` ->process($_POST) ->json(function ($response) { // Modify the response to return 1=success, 0=failed if ($response['status'] === 'ok') { $response['data'] = 1; // Success } else { $response['data'] = 0; // Failed } return $response; }); `
Sign In or Register to comment.