self join not display dropdown
self join not display dropdown
dominic@suvantech.com
Posts: 1Questions: 1Answers: 0
var editor;
editor = new $.fn.dataTable.Editor( {
ajax: "vendor/plugins/datatables/extensions/Editor/examples/php/joinSelf.php",
table: "#joinself",
fields: [ {
label: "First name:",
name: "users.first_name"
}, {
label: "Last name:",
name: "users.last_name"
}, {
label: "Manager:",
name: "users.manager",
type: "select",
}
]
} );
$('#joinself').DataTable( {
dom: '<"dt-panelmenu clearfix"Tfr>t<"dt-panelfooter clearfix"ip>',
ajax: "vendor/plugins/datatables/extensions/Editor/examples/php/joinSelf.php",
columns: [
{ data: "users.first_name" },
{ data: "users.last_name" },
{
data: "manager",
render: function ( val, type, row ) {
return val.first_name ?
val.first_name +' '+ val.last_name :
'';
},
defaultContent: ""
}
],
tableTools: {
sRowSelect: "os",
aButtons: [{
sExtends: "editor_create",
editor: editor
}, {
sExtends: "editor_edit",
editor: editor
}, {
sExtends: "editor_remove",
editor: editor
}]
}
} );
} );
<?php
// DataTables PHP library
include( "../../php/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;
/*
* Example PHP implementation used for the joinSelf.html example - the basic idea
* here is that the join performed is simply to get extra information about the
* 'manager' (in this case, the name of the manager). To alter the manager for
* a user, you would change the 'manager' value in the 'users' table, so the
* information from the join is read-only.
*/
$out = Editor::inst( $db, 'users' )
->field(
Field::inst( 'users.first_name' ),
Field::inst( 'users.last_name' ),
Field::inst( 'users.manager' ),
Field::inst( 'manager.first_name' ),
Field::inst( 'manager.last_name' )
)
->leftJoin( 'users as manager', 'users.manager', '=', 'manager.id' )
->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']) ) {
$userList = $db->select( 'users', 'id, first_name, last_name' );
$out['userList'] = array();
while ( $row = $userList->fetch() ) {
$out['userList'][] = array(
"value" => $row['id'],
"label" => $row['id'].' '.$row['first_name'].' '.$row['last_name']
);
}
}
// Send it back to the client
echo json_encode( $out );
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
Could you provide a description of what is currently happening, and what you would like to happen please. Also if you could provide a link to the page so I can debug it live that would be useful.
Allan