Stack Overflow Questions Tags Users Badges Unanswered Ask Question Add r

Stack Overflow Questions Tags Users Badges Unanswered Ask Question Add r

temerariomalagatemerariomalaga Posts: 16Questions: 0Answers: 0
edited March 2014 in General
I have a database with a table Grupos and a table CLIENTES. The id of Grupos's table is foreign key in Clientes's table. I put a combobox in the add record form for add the id of Grupos and I need to fill that combobox with Grupos data. I've found in the tutorial of datatables the code for do that but when I try to show the table it doesn't appear. I put here the code of the js and php file.
js
[code](function($){

$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "php/table.CLIENTES.php",
"domTable": "#CLIENTES",
"fields": [
{
"label": "NIF",
"name": "NIF",
"type": "text"
},
{
"label": "Nombre",
"name": "Nombre",
"type": "text"
},
{
"label": "Direccion",
"name": "Direccion",
"type": "text"
},
{
"label": "Localidad",
"name": "Localidad",
"type": "text"
},
{
"label": "CP",
"name": "CP",
"type": "text"
},
{
"label": "Telefono",
"name": "Telofono",
"type": "text"
},
{
"label": "Email",
"name": "Email",
"type": "text"
},
{
"label": "Cod_grupo",
"name": "Cod_grupo",
"type": "select"
}
]
} );

$('#CLIENTES').dataTable( {
"sDom": "Tfrtip",
"sAjaxSource": "php/table.CLIENTES.php",
"aoColumns": [
{
"mData": "NIF"
},
{
"mData": "Nombre"
},
{
"mData": "Direccion"
},
{
"mData": "Localidad"
},
{
"mData": "CP"
},
{
"mData": "Telofono"
},
{
"mData": "Email"
},
{
"mData": "Cod_grupo" ,
"mRender" : function ( val, type, row ) {
if ( val ) {
return val + ' ' + row.GRUPOS.Descripcion;
}
return "" ;
}
"sDefaultContent" : ""
}
],
"oTableTools": {
"sRowSelect": "multi",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
},
"fnInitComplete" : function ( settings, json ) {
editor.field( 'Cod_grupo' ).update( json.userList );
}
} );
}(jQuery));
[/code]
php
[code]
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, 'CLIENTES' )
->fields(
Field::inst( 'NIF' ),
Field::inst( 'Nombre' ),
Field::inst( 'Direccion' ),
Field::inst( 'Localidad' ),
Field::inst( 'CP' ),
Field::inst( 'Telofono' ),
Field::inst( 'Email' ),
Field::inst( 'Grupo', 'Cod_grupo' )
->join(
Join::inst( 'CLIENTES, object' )
->aliasParentTable( 'GRUPOS' )
->name( 'Cod_grupo' )
->join( 'Cod_grupo', 'Cod_grupo' )
->set( false )
->field(
Field::inst( 'GRUPOS.Descripcion' , 'Descripcion' )
)
);
$out = $editor
->process( $_POST )
->data();
if ( !isset( $_POST [ 'action' ]) ) {
$grouplist = $db ->select( 'CLIENTES', 'Cod_grupo, Descripcion' );
$out [ 'grouplist' ] = array();
while ( $row = $grouplist ->fetch() ) {
$out [ 'grouplist' ][] = array (
"value" => $row [ 'Cod_grupo' ],
"label" => $row [ 'Cod_grupo' ]. ' ' . $row [ 'Descripcion' ]
);
}
}
echo json_encode( $out );
[/code]

Replies

  • allanallan Posts: 63,299Questions: 1Answers: 10,431 Site admin
    When you say the data doesn't appear - what does happen? Presumably there is an error in the server somewhere? Is there anything indicated in the server error log or the Ajax return? Can you link us to the page?

    Allan
  • temerariomalagatemerariomalaga Posts: 16Questions: 0Answers: 0
    I found the problem, I was not writing the combo correctly. I used the generator and it works well.
This discussion has been closed.