Collection editor with data from database

Collection editor with data from database

fabioberettafabioberetta Posts: 74Questions: 23Answers: 4

Hello,

I need to use this example:

http://editor.datatables.net/examples/standalone/collection.html

but I would like to use it collecting the data from a database. I would like to use the PHP scirpts to load the data.

I am trying to call the script in this way but it does not work:

$.ajax( {
                    url: '_php/dtMedicalInfo.php?child_id='+child_id,
                    method: 'POST',
                    dataType: 'json',
                    data: {action: 'read', data: {} },
                    xhrFields: {
                        withCredentials: true
            },
                    success: function (json) {
                        
                        for ( var i=0, ien=json.data.length ; i<ien ; i++ ) {
                createPanel( json.data[i] );
            }
                    
                    } 
                
                } )

The PHP is the following.

include( "../vendor/Editor-1.5.0/php/DataTables.php" );

// start session to get session user data
session_start();

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Join,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;

// Sets the filter of the table 
$filter = isset($_GET['child_id'])?$_GET['child_id']:0; //filter recordset according to currently selected row


if (isset($_POST['filter_id'])) {
    $filter = $_POST['filter_id'];
    unset( $_POST['filter_id'] );
}
 
 
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'medical_info', 'id' )
    ->fields(
        Field::inst( 'medical_info.doctor_first_name' ),
        Field::inst( 'medical_info.doctor_last_name' ),
        Field::inst( 'medical_info.medical_note' ),
        Field::inst( 'medical_info.doctor_phone' ),
        Field::inst( 'medical_info.note' ),
        Field::inst( 'medical_info.child_id' )
            ->set( Field::SET_CREATE )
            ->setValue( $filter ),
        Field::inst( 'child.account_id' ) )
        
    ->where( 'medical_info.child_id', $filter )
    ->leftJoin( 'child', 'medical_info.child_id', '=', 'child.id' )
    ->process( $_POST )
    ->json();

I get this reply from the server.

<br />
<b>Notice</b>:  Undefined index: data in <b>/Users/fabio_beretta/Sites/LutinRouge_admin/vendor/Editor-1.5.0/php/Editor/Editor.php</b> on line <b>573</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/Users/fabio_beretta/Sites/LutinRouge_admin/vendor/Editor-1.5.0/php/Editor/Editor.php</b> on line <b>573</b><br />
{"data":[]}

What am I doing wrong? How shall I call the php script to get the query result?

ty
f

This discussion has been closed.