Datatables Editor cannot create new entry with join tables

Datatables Editor cannot create new entry with join tables

BuSHariBuSHari Posts: 13Questions: 0Answers: 0
edited June 2013 in Editor
Hello,

I`ve created a simple join through that document
http://editor.datatables.net/release/DataTables/extras/Editor/examples/join.html

When trying to create a new entry i`m getting an error:
[code]Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`ci_tools`.`dashboard_task`, CONSTRAINT `FRG_KEY_PRT` FOREIGN KEY (`priority`) REFERENCES `dashboard_priority` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)'[/code]

PHP
[code]<?php

/*
* Editor server script for DB table dashboard_task
* Automatically generated by http://editor.datatables.net/generator
*/

// DataTables PHP library
include( "lib/DataTables.php" );

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


// Build our Editor instance and process the data coming from _POST
$editor = Editor::inst( $db, 'dashboard_task' )
->fields(
Field::inst( 'task' )
->validator( 'Validate::required' ),
Field::inst( 'priority' ),
Field::inst( 'owner' )
->validator( 'Validate::required' ),
Field::inst( 'sdate' )
->validator( 'Validate::dateFormat_required', 'D, j M Y' )
->getFormatter( 'Format::date_sql_to_format', 'D, j M Y' )
->setFormatter( 'Format::date_format_to_sql', 'D, j M Y' ),
Field::inst( 'ddate' )
->validator( 'Validate::dateFormat_required', 'D, j M Y' )
->getFormatter( 'Format::date_sql_to_format', 'D, j M Y' )
->setFormatter( 'Format::date_format_to_sql', 'D, j M Y' ),
Field::inst( 'adate' )
->getFormatter( 'Format::date_sql_to_format', 'D, j M Y' )
->setFormatter( 'Format::date_format_to_sql', 'D, j M Y' ),
Field::inst( 'status' ),
Field::inst( 'quarter' ),
Field::inst( 'remarks' )
)
->join(
Join::inst( 'dashboard_priority', 'object' )
->join( 'priority', 'id' )
->field(
Field::inst( 'id' )->validator( 'Validate::required' ),
Field::inst( 'name' )
),
Join::inst( 'dashboard_status', 'object' )
->join( 'status', 'id' )
->field(
Field::inst( 'id' )->validator( 'Validate::required' ),
Field::inst( 'name' )
)
);

// The "process" method will handle data get, create, edit and delete
// requests from the client

$out = $editor
->process($_POST)
->data();


// When there is no 'action' parameter we are getting data, and in this
// case we want to send extra data back to the client, with the options
// for the 'department' select list and 'access' radio boxes
if ( !isset($_POST['action']) ) {
// Get department details
$out['dashboard_priority'] = $db
->select( 'dashboard_priority', 'id as value, name as label' )
->fetchAll();
$out['dashboard_status'] = $db
->select( 'dashboard_status', 'id as value, name as label' )
->fetchAll();

}

// Send it back to the client
echo json_encode( $out );

[/code]

JavaScript
[code]
/*
* Editor client script for DB table dashboard_task
* Automatically generated by http://editor.datatables.net/generator
*/

(function($){

$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "php/table.dashboard_task.php",
"domTable": "#dashboard_task",
"fields": [
{
"label": "Task",
"name": "task",
"type": "text"
},
{
"label": "Priority",
"name": "dashboard_task.priority",
"type": "select"
},
{
"label": "Owner",
"name": "owner",
"type": "text"
},
{
"label": "Start Date",
"name": "sdate",
"type": "date",
"dateFormat": "D, d M yy",
"dateImage": "images\/calender.png"
},
{
"label": "Due Date",
"name": "ddate",
"type": "date",
"dateFormat": "D, d M yy",
"dateImage": "images\/calender.png"
},
{
"label": "Actual Date",
"name": "adate",
"type": "date",
"dateFormat": "D, d M yy",
"dateImage": "images\/calender.png"
},
{
"label": "Status",
"name": "dashboard_task.status",
"type": "select"
},
{
"label": "Quarter",
"name": "quarter",
"type": "text"
},
{
"label": "Remarks",
"name": "remarks",
"type": "text"
}
]
} );

$('#dashboard_task').dataTable( {
"sDom": "<'row-fluid'<'span6'T><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sAjaxSource": "php/table.dashboard_task.php",
"aoColumns": [
{
"mData": "task"
},
{
"mData": "dashboard_priority.name" , "sClass": "center"
},
{
"mData": "owner" , "sClass": "center"
},
{
"mData": "sdate" , "sClass": "center"
},
{
"mData": "ddate" , "sClass": "center"
},
{
"mData": "adate" , "sClass": "center"
},
{
"mData": "dashboard_status.name"
},
{
"mData": "quarter"
},
{
"mData": "remarks"
}
],
"oTableTools": {
"sRowSelect": "multi",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
},
"fnInitComplete": function ( settings, json ) {
// Set the allowed values for the select and radio fields based on
// what is available in the database
editor.field('dashboard_task.priority').update( json.dashboard_priority );
editor.field('dashboard_task.status').update( json.dashboard_status );
}
} );

} );

}(jQuery));

[/code]


DataTables debugger:
http://debug.datatables.net/ukoqoq

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    It looks like what is happening is that the priority being set isn't available in the `dashboard_priority` table. Are you creating new priorities on the fly and submitting them with the rest of the content? Actually, it would be useful to see what is being submitted to the server for a create if that is possible please.

    The way the Join class works in Editor is that the main table is updated first, then the join elements. It might be that you need them the other way around, but I don't quite understand how the reference works that way around.

    Allan
  • BuSHariBuSHari Posts: 13Questions: 0Answers: 0
    edited June 2013
    Hi Allan,

    I`m not trying to create a new priorities i have a fixed list in the tables "dashboard_priority" and in "dashboard_status", The tables contain the columns "id" & "name"
    and this is what they contain:
    dashboard_priority:
    id name
    1 Very Low
    2 Low
    3 Medium
    4 High
    5 Very High

    dashboard_status:
    id name
    1 Not Started
    2 Started
    3 In Progress
    4 Paused
    5 Done

    dashboard_task is the parent table
  • BuSHariBuSHari Posts: 13Questions: 0Answers: 0
    Forgot to mention that i`m trying to update the ids of 'priority' & 'status' in dashboard_task table
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Can you show me the data that is being submitted in the ajax request?

    Allan
  • BuSHariBuSHari Posts: 13Questions: 0Answers: 0
    I`ve sent you the DataTables debugger, can`t you see it there?
    if not, how can i find the ajax request?
  • BuSHariBuSHari Posts: 13Questions: 0Answers: 0
    edited June 2013
    Can you please tell me how to do it?

    Thanks.
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Sorry I should have explained. In Chrome use the Developer tools, or in Firefox use Firebug (the Firefox dev tools probably would do as well) - using them you will be able to see the Ajax request being made in the 'network' (might be called 'resources') pane. In there, you will be able to see both what is sent and what is received by the Ajax request. In this case we are interested in seeing what data is being sent to the server.

    Many thanks,
    Allan
  • BuSHariBuSHari Posts: 13Questions: 0Answers: 0
    edited June 2013
    I thought that what i`ve sent you in the first post, is good cause i `ve done the same thing.
    So i`m sending you now the whole response

    POST:
    [code]action=create
    data[adate]=
    data[dashboard_priority][id]=1
    data[dashboard_status][id]=1
    data[ddate]=Sat, 15 Jun 2013
    data[owner]=jjjjj
    data[quarter]=
    data[remarks]=
    data[sdate]=Sat, 8 Jun 2013
    data[task]=hhhhh
    id=
    table=[/code]

    HAR:
    [code]{
    "log": {
    "version": "1.2",
    "creator": {
    "name": "WebInspector",
    "version": "537.36"
    },
    "pages": [
    {
    "startedDateTime": "2013-06-06T07:10:32.430Z",
    "id": "page_13",
    "title": "http://localhost:8080/Dashboard2/",
    "pageTimings": {
    "onContentLoad": 310,
    "onLoad": 330
    }
    }
    ],
    "entries": [
    {
    "startedDateTime": "2013-06-06T07:10:48.128Z",
    "time": 587,
    "request": {
    "method": "POST",
    "url": "http://localhost:8080/Dashboard2/php/table.dashboard_task.php",
    "httpVersion": "HTTP/1.1",
    "headers": [
    {
    "name": "Cookie",
    "value": "_pk_id.1.1fff=1bdf590c62fcb919.1367418169.3.1369925118.1369922162."
    },
    {
    "name": "Origin",
    "value": "http://localhost:8080"
    },
    {
    "name": "Accept-Encoding",
    "value": "gzip,deflate,sdch"
    },
    {
    "name": "Host",
    "value": "localhost:8080"
    },
    {
    "name": "Accept-Language",
    "value": "en-US,en;q=0.8"
    },
    {
    "name": "User-Agent",
    "value": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.29 Safari/537.36"
    },
    {
    "name": "Content-Type",
    "value": "application/x-www-form-urlencoded; charset=UTF-8"
    },
    {
    "name": "Accept",
    "value": "application/json, text/javascript, */*; q=0.01"
    },
    {
    "name": "Referer",
    "value": "http://localhost:8080/Dashboard2/"
    },
    {
    "name": "X-Requested-With",
    "value": "XMLHttpRequest"
    },
    {
    "name": "Connection",
    "value": "keep-alive"
    },
    {
    "name": "Content-Length",
    "value": "266"
    }
    ],
    "queryString": [],
    "cookies": [
    {
    "name": "_pk_id.1.1fff",
    "value": "1bdf590c62fcb919.1367418169.3.1369925118.1369922162.",
    "expires": null,
    "httpOnly": false,
    "secure": false
    }
    ],
    "headersSize": 621,
    "bodySize": 266,
    "postData": {
    "mimeType": "application/x-www-form-urlencoded; charset=UTF-8",
    "text": "action=create&table=&id=&data%5Btask%5D=bbbb&data%5Bdashboard_priority%5D%5Bid%5D=1&data%5Bowner%5D=bbbbb&data%5Bsdate%5D=Fri%2C+7+Jun+2013&data%5Bddate%5D=Fri%2C+14+Jun+2013&data%5Badate%5D=&data%5Bdashboard_status%5D%5Bid%5D=1&data%5Bquarter%5D=&data%5Bremarks%5D=",
    "params": [
    {
    "name": "action",
    "value": "create"
    },
    {
    "name": "table",
    "value": ""
    },
    {
    "name": "id",
    "value": ""
    },
    {
    "name": "data%5Btask%5D",
    "value": "bbbb"
    },
    {
    "name": "data%5Bdashboard_priority%5D%5Bid%5D",
    "value": "1"
    },
    {
    "name": "data%5Bowner%5D",
    "value": "bbbbb"
    },
    {
    "name": "data%5Bsdate%5D",
    "value": "Fri%2C+7+Jun+2013"
    },
    {
    "name": "data%5Bddate%5D",
    "value": "Fri%2C+14+Jun+2013"
    },
    {
    "name": "data%5Badate%5D",
    "value": ""
    },
    {
    "name": "data%5Bdashboard_status%5D%5Bid%5D",
    "value": "1"
    },
    {
    "name": "data%5Bquarter%5D",
    "value": ""
    },
    {
    "name": "data%5Bremarks%5D",
    "value": ""
    }
    ]
    }
    },
    "response": {
    "status": 200,
    "statusText": "OK",
    "httpVersion": "HTTP/1.1",
    "headers": [
    {
    "name": "Date",
    "value": "Thu, 06 Jun 2013 07:10:48 GMT"
    },
    {
    "name": "Server",
    "value": "Apache/2.4.2 (Win32) PHP/5.4.6"
    },
    {
    "name": "Connection",
    "value": "Keep-Alive"
    },
    {
    "name": "X-Powered-By",
    "value": "PHP/5.4.6"
    },
    {
    "name": "Content-Length",
    "value": "1190"
    },
    {
    "name": "Keep-Alive",
    "value": "timeout=5, max=100"
    },
    {
    "name": "Content-Type",
    "value": "text/html"
    }
    ],
    "cookies": [],
    "content": {
    "size": 1190,
    "mimeType": "text/html",
    "compression": 0
    },
    "redirectURL": "",
    "headersSize": 224,
    "bodySize": 1190
    },
    "cache": {},
    "timings": {
    "blocked": 0,
    "dns": 1,
    "connect": -1,
    "send": 0,
    "wait": 584,
    "receive": 1,
    "ssl": -1
    },
    "pageref": "page_13"
    }
    ]
    }
    }
    [/code]
  • BuSHariBuSHari Posts: 13Questions: 0Answers: 0
    is that info helps?

    Thanks a lot for your help
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Very much so, thank you for posting it.

    In your main Editor instance you have this line of code:

    > Field::inst( 'priority' ),

    However, there is no `priority` field information being sent as part of the create request (there is no `priority` field in the Editor instance). I think it is this discrepancy that is causing the problem.

    What was the intention here?

    Many thanks,
    Allan
  • BuSHariBuSHari Posts: 13Questions: 0Answers: 0
    OK Thanks for your help...
    But if i remove that line, i`m getting that error:

    [code]{"sError":"Join was performed on the field 'priority' which was not included in the Editor field list. The join field must be included as a regular field in the Editor instance."}[/code]
  • BuSHariBuSHari Posts: 13Questions: 0Answers: 0
    Hello,

    I saw that thread that it similar to my problem:
    https://www.datatables.net/forums/discussion/11278/editor-with-join#Item_13

    So i`ve looked into that example:
    http://editor.datatables.net/release/DataTables/extras/Editor/examples/joinSelf.html

    and now i`ve succeeded to create a new entry, but i`m getting other error.

    The row is created in the DB, but in the dialog screen it give me an error:
    [code]An error has occurred - Please contact the system administrator[/code]

    Screenshot:
    http://img51.imageshack.us/img51/3473/dashboardt.jpg

    AJAX Response:
    [code]INSERT INTO `dashboard_task` ( `task`, `priority`, `owner`, `sdate`, `ddate`, `adate`, `status`, `quarter`, `remarks` ) VALUES ( :task, :priority, :owner, :sdate, :ddate, :adate, :status, :quarter, :remarks )
    {"id":"row_118","error":"","fieldErrors":[],"data":[],"row":{"DT_RowId":"row_118","id":"118","project":null,"task":"ddddd","priority":{"id":"4","name":"High"},"owner":"ddddd","sdate":"Thu, 13 Jun 2013","ddate":"Thu, 27 Jun 2013","adate":"","status":{"id":"1","name":"Not Started"},"quarter":"","remarks":""}}[/code]


    PHP:
    [code]<?php

    /*
    * Editor server script for DB table dashboard_task
    * Automatically generated by http://editor.datatables.net/generator
    */

    // DataTables PHP library
    include( "lib/DataTables.php" );

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


    // Build our Editor instance and process the data coming from _POST
    $editor = Editor::inst( $db, 'dashboard_task' )
    ->fields(
    Field::inst( 'id' )->set( false ),
    Field::inst( 'project' )->set( false ),
    Field::inst( 'task' )
    ->validator( 'Validate::required' ),
    Field::inst( 'priority' ),
    Field::inst( 'owner' )
    ->validator( 'Validate::required' ),
    Field::inst( 'sdate' )
    ->validator( 'Validate::dateFormat_required', 'D, j M Y' )
    ->getFormatter( 'Format::date_sql_to_format', 'D, j M Y' )
    ->setFormatter( 'Format::date_format_to_sql', 'D, j M Y' ),
    Field::inst( 'ddate' )
    ->validator( 'Validate::dateFormat_required', 'D, j M Y' )
    ->getFormatter( 'Format::date_sql_to_format', 'D, j M Y' )
    ->setFormatter( 'Format::date_format_to_sql', 'D, j M Y' ),
    Field::inst( 'adate' )
    ->getFormatter( 'Format::date_sql_to_format', 'D, j M Y' )
    ->setFormatter( 'Format::date_format_to_sql', 'D, j M Y' ),
    Field::inst( 'status' ),
    Field::inst( 'quarter' ),
    Field::inst( 'remarks' )
    )
    ->join(
    Join::inst( 'dashboard_priority', 'object' ) // Read from 'users' table
    ->aliasParentTable( 'priority' ) // i.e. FROM users as manager
    ->name( 'priority' ) // JSON / POST field
    ->join( 'priority', 'id' ) // Join parent `id`, to child `manager`
    ->set( false ) // Used for read-only (change the 'manager' on the parent to change the value)
    ->field(
    Field::inst( 'dashboard_priority.id', 'id' ),
    Field::inst( 'dashboard_priority.name', 'name' )
    ),
    Join::inst( 'dashboard_status', 'object' ) // Read from 'users' table
    ->aliasParentTable( 'status' ) // i.e. FROM users as manager
    ->name( 'status' ) // JSON / POST field
    ->join( 'status', 'id' ) // Join parent `id`, to child `manager`
    ->set( false ) // Used for read-only (change the 'manager' on the parent to change the value)
    ->field(
    Field::inst( 'dashboard_status.id', 'id' ),
    Field::inst( 'dashboard_status.name', 'name' )
    )
    );


    // The "process" method will handle data get, create, edit and delete
    // requests from the client

    $out = $editor
    ->process($_POST)
    ->data();


    // When there is no 'action' parameter we are getting data, and in this
    // case we want to send extra data back to the client, with the options
    // for the 'department' select list and 'access' radio boxes
    if ( !isset($_POST['action']) ) {
    $priorityList = $db->select( 'dashboard_priority', 'id, name' );

    $out['priorityList'] = array();
    while ( $row = $priorityList->fetch() ) {
    $out['priorityList'][] = array(
    "value" => $row['id'],
    "label" => $row['name']
    );
    }
    $statusList = $db->select( 'dashboard_status', 'id, name' );

    $out['statusList'] = array();
    while ( $row = $statusList->fetch() ) {
    $out['statusList'][] = array(
    "value" => $row['id'],
    "label" => $row['name']
    );
    }
    }

    // Send it back to the client
    echo json_encode( $out );

    [/code]

    JavaScript:
    [code]
    /*
    * Editor client script for DB table dashboard_task
    */

    (function($){

    $(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
    "ajaxUrl": "php/table.dashboard_task.php",
    "domTable": "#dashboard_task",
    "fields": [
    {
    "label": "Task",
    "name": "task",
    "type": "text"
    },
    {
    "label": "Priority",
    "name": "priority",
    "type": "select"
    },
    {
    "label": "Owner",
    "name": "owner",
    "type": "text"
    },
    {
    "label": "Start Date",
    "name": "sdate",
    "type": "date",
    "dateFormat": "D, d M yy",
    "dateImage": "images\/calender.png"
    },
    {
    "label": "Due Date",
    "name": "ddate",
    "type": "date",
    "dateFormat": "D, d M yy",
    "dateImage": "images\/calender.png"
    },
    {
    "label": "Actual Date",
    "name": "adate",
    "type": "date",
    "dateFormat": "D, d M yy",
    "dateImage": "images\/calender.png"
    },
    {
    "label": "Status",
    "name": "status",
    "type": "select"
    },
    {
    "label": "Quarter",
    "name": "quarter",
    "type": "text"
    },
    {
    "label": "Remarks",
    "name": "remarks",
    "type": "text"
    }
    ]
    } );

    $('#dashboard_task').dataTable( {
    "sDom": "<'row-fluid'<'span6'T><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
    "sAjaxSource": "php/table.dashboard_task.php",
    "aoColumns": [
    {
    "mData": "task"
    },
    {
    "mData": "priority.name" , "sClass": "center"
    },
    {
    "mData": "owner" , "sClass": "center"
    },
    {
    "mData": "sdate" , "sClass": "center"
    },
    {
    "mData": "ddate" , "sClass": "center"
    },
    {
    "mData": "adate" , "sClass": "center"
    },
    {
    "mData": "status.name" , "sClass": "center"
    },
    {
    "mData": "quarter"
    },
    {
    "mData": "remarks"
    }
    ],
    "oTableTools": {
    "sRowSelect": "multi",
    "aButtons": [
    { "sExtends": "editor_create", "editor": editor },
    { "sExtends": "editor_edit", "editor": editor },
    { "sExtends": "editor_remove", "editor": editor }
    ]
    },
    "fnInitComplete": function ( settings, json ) {
    // Set the allowed values for the select and radio fields based on
    // what is available in the database
    editor.field('priority').update( json.priorityList );
    editor.field('status').update( json.statusList );

    }
    } );

    } );

    }(jQuery));

    [/code]
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Ah I see. Good to hear that you've been able to make progress with this.

    It looks like there is an echo of the SQL statement that is being generated somewhere. Have you modified any of the Editor library PHP files? I've just had a look at the Editor 1.2.3 files and there doesn't appear to be a 'spare' echo anywhere.

    It might be worth having a look through the library files to see if there is an extraneous echo somewhere.

    Regards,
    Allan
  • BuSHariBuSHari Posts: 13Questions: 0Answers: 0
    Ahhhhhh, I cannot believe that i was stuck on this stupid issue!
    Thanks a lot that worked!
    i had an echo at "Query.php" in MySql folder

    Now, maybe we can help me with a little issue that i`m trying to figure it out.

    I`m trying to do join to some tables:
    I`ve the parent table "dashboard_task"
    in there i have a FK "project" that is connected to "id" in the table "dashboard_project"
    in "dashboard_project" i have the columns:
    "id" - id of the project
    "name" - name of the project
    "track_id" - is a FK that is connected to "id" in the table "dashboard_track"
    in "dashboard_track" i have the columns:
    "id" - id of the track
    "name" - name of the track

    How can i do the join between them?
  • BuSHariBuSHari Posts: 13Questions: 0Answers: 0
    I`ve tried to do it, but with no luck...

    PHP:
    [code]<?php

    /*
    * Editor server script for DB table dashboard_task
    * Automatically generated by http://editor.datatables.net/generator
    */

    // DataTables PHP library
    include( "lib/DataTables.php" );

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


    // Build our Editor instance and process the data coming from _POST
    $editor = Editor::inst( $db, 'dashboard_task' )
    ->fields(
    Field::inst( 'id' )->set( false ),
    Field::inst( 'project' ),
    Field::inst( 'task' )
    ->validator( 'Validate::required' ),
    Field::inst( 'priority' )
    ->validator( 'Validate::required' ),
    Field::inst( 'owner' )
    ->validator( 'Validate::required' ),
    Field::inst( 'sdate' )
    ->validator( 'Validate::dateFormat_required', 'D, j M Y' )
    ->getFormatter( 'Format::date_sql_to_format', 'D, j M Y' )
    ->setFormatter( 'Format::date_format_to_sql', 'D, j M Y' ),
    Field::inst( 'ddate' )
    ->validator( 'Validate::dateFormat_required', 'D, j M Y' )
    ->getFormatter( 'Format::date_sql_to_format', 'D, j M Y' )
    ->setFormatter( 'Format::date_format_to_sql', 'D, j M Y' ),
    Field::inst( 'adate' )
    ->getFormatter( 'Format::date_sql_to_format', 'D, j M Y' )
    ->setFormatter( 'Format::date_format_to_sql', 'D, j M Y' ),
    Field::inst( 'status' )
    ->validator( 'Validate::required' ),
    Field::inst( 'quarter' ),
    Field::inst( 'remarks' )
    )
    ->join(
    Join::inst( 'dashboard_priority', 'object' ) // Read from 'users' table
    ->aliasParentTable( 'priority' ) // i.e. FROM users as manager
    ->name( 'priority' ) // JSON / POST field
    ->join( 'priority', 'id' ) // Join parent `id`, to child `manager`
    ->set( false ) // Used for read-only (change the 'manager' on the parent to change the value)
    ->field(
    Field::inst( 'id' ),
    Field::inst( 'name' )
    ),
    Join::inst( 'dashboard_status', 'object' ) // Read from 'users' table
    ->aliasParentTable( 'status' ) // i.e. FROM users as manager
    ->name( 'status' ) // JSON / POST field
    ->join( 'status', 'id' ) // Join parent `id`, to child `manager`
    ->set( false ) // Used for read-only (change the 'manager' on the parent to change the value)
    ->field(
    Field::inst( 'id' ),
    Field::inst( 'name' )
    ),
    Join::inst( 'dashboard_project', 'object' )
    ->aliasParentTable( 'project' )
    ->name( 'project' )
    ->join(
    array( 'project', 'id' ),
    array( 'track_id', 'id' ),
    'dashboard_track'
    )
    ->set( false )
    ->field(
    Field::inst( 'id' ),
    Field::inst( 'name' ),
    Field::inst( 'track_id' )
    )
    );


    // The "process" method will handle data get, create, edit and delete
    // requests from the client

    $out = $editor
    ->process($_POST)
    ->data();


    // When there is no 'action' parameter we are getting data, and in this
    // case we want to send extra data back to the client, with the options
    // for the 'department' select list and 'access' radio boxes
    if ( !isset($_POST['action']) ) {
    $priorityList = $db->select( 'dashboard_priority', 'id, name' );

    $out['priorityList'] = array();
    while ( $row = $priorityList->fetch() ) {
    $out['priorityList'][] = array(
    "value" => $row['id'],
    "label" => $row['name']
    );
    }
    $statusList = $db->select( 'dashboard_status', 'id, name' );

    $out['statusList'] = array();
    while ( $row = $statusList->fetch() ) {
    $out['statusList'][] = array(
    "value" => $row['id'],
    "label" => $row['name']
    );
    }
    $trackList = $db->select( 'dashboard_track', 'id, name' );

    $out['trackList'] = array();
    while ( $row = $trackList->fetch() ) {
    $out['trackList'][] = array(
    "value" => $row['id'],
    "label" => $row['name']
    );
    }
    $projectList = $db->select( 'dashboard_project', 'id, name, track_id' );

    $out['projectList'] = array();
    while ( $row = $projectList->fetch() ) {
    $out['projectList'][] = array(
    "value" => $row['id'],
    "label" => $row['name']
    );
    }

    }

    // Send it back to the client
    echo json_encode( $out );

    [/code]


    JS:
    [code]
    /*
    * Editor client script for DB table dashboard_task
    */

    (function($){

    $(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
    "ajaxUrl": "php/table.dashboard_task.php",
    "domTable": "#dashboard_task",
    "fields": [
    {
    "label": "Track",
    "name": "track",
    "type": "select"
    },
    {
    "label": "Project",
    "name": "project",
    "type": "select"
    },
    {
    "label": "Task",
    "name": "task",
    "type": "text"
    },
    {
    "label": "Priority",
    "name": "priority",
    "type": "select"
    },
    {
    "label": "Owner",
    "name": "owner",
    "type": "text"
    },
    {
    "label": "Start Date",
    "name": "sdate",
    "type": "date",
    "dateFormat": "D, d M yy",
    "dateImage": "images\/calender.png"
    },
    {
    "label": "Due Date",
    "name": "ddate",
    "type": "date",
    "dateFormat": "D, d M yy",
    "dateImage": "images\/calender.png"
    },
    {
    "label": "Actual Date",
    "name": "adate",
    "type": "date",
    "dateFormat": "D, d M yy",
    "dateImage": "images\/calender.png"
    },
    {
    "label": "Status",
    "name": "status",
    "type": "select"
    },
    {
    "label": "Quarter",
    "name": "quarter",
    "type": "text"
    },
    {
    "label": "Remarks",
    "name": "remarks",
    "type": "text"
    }
    ]
    } );

    $('#dashboard_task').dataTable( {
    "sDom": "<'row-fluid'<'span6'T><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
    "sAjaxSource": "php/table.dashboard_task.php",
    "aoColumns": [
    {
    "mData": "track.name", "sDefaultContent": ""
    },
    {
    "mData": "project.name", "sDefaultContent": ""
    },
    {
    "mData": "task"
    },
    {
    "mData": "priority.name", "sDefaultContent": ""
    },
    {
    "mData": "owner"
    },
    {
    "mData": "sdate"
    },
    {
    "mData": "ddate"
    },
    {
    "mData": "adate"
    },
    {
    "mData": "status.name", "sDefaultContent": ""
    },
    {
    "mData": "quarter"
    },
    {
    "mData": "remarks"
    }
    ],
    "oTableTools": {
    "sRowSelect": "multi",
    "aButtons": [
    { "sExtends": "editor_create", "editor": editor },
    { "sExtends": "editor_edit", "editor": editor },
    { "sExtends": "editor_remove", "editor": editor }
    ]
    },
    "fnInitComplete": function ( settings, json ) {
    // Set the allowed values for the select and radio fields based on
    // what is available in the database
    editor.field('priority').update( json.priorityList );
    editor.field('status').update( json.statusList );
    editor.field('project').update( json.projectList );
    editor.field('track').update( json.trackList );

    }
    } );

    } );

    }(jQuery));

    [/code]
  • BuSHariBuSHari Posts: 13Questions: 0Answers: 0
    Allan, can you please help me with that?

    Thanks a lot for all your help...
  • BuSHariBuSHari Posts: 13Questions: 0Answers: 0
    Sorry for bumping this,

    But can you please help me?
    i`m stuck with that join...
This discussion has been closed.