数据表编辑器 - 在同一页面上添加两个不同的不相关SQL表 -

时间:2017-06-22 10:50:07

标签: javascript jquery datatables

早上好,伙计们, 我试图在同一页面上添加同一个db(Database1)的两个不同的不相关的SQL表(table1-table2)。 第一个表(table1)正常工作但第二个表(table2)未加载,报告的错误如下(DataTables警告:表id = ID-ajax错误。有关此错误的详细信息,请参阅)。 我读了这个链接,但我无法理解我错在哪里,(我很高兴......)你能帮助我吗?

这是我的代码:

的config.php

enter code here
<?php if (!defined('DATATABLES')) exit(); // Ensure being used in DataTables env.

 // Enable error reporting for debugging (remove for production)
error_reporting(E_ALL);
ini_set('display_errors', '1');

$sql_details = array(
"type" => "Mysql",  // Database type: "Mysql", "Postgres", "Sqlserver",             "Sqlite" or "Oracle"
"user" => "root",       // Database user name
"pass" => "admin",       // Database password
"host" => "localhost",       // Database host
"port" => "",       // Database connection port (can be left empty for default)
"db"   => "Database1",       // Database name
"dsn"  => ""        // PHP DSN extra information. Set as `charset=utf8` if you are using MySQL
);

的index.html

enter code here
Tableone = new $.fn.dataTable.Editor
   $('#table1').DataTable( {
      dom: 'Bfrtip',
      ajax: "../php/staff.php",
              type: 'POST',
              scrollX: true,
      pageLength: 12,
      columns: [
          { data: "table1.field1" },
          { data: "table1.field2" },
          { data: "table1.field3", render: $.fn.dataTable.render.number( '.', ',', 0, '€ ' ) },
          { data: "table1.field4" },
          { data: "table1.field5" },
      ],
       columnDefs: [
               {targets: 0, visible: true},
               {targets: 1, visible: true},
               {targets: 2, visible: true},
               {targets: 3, visible: false},
               {targets: 4, visible: true},
            ],
             fixedColumns: true,
              select: true,
                     buttons: [
                  {extend: 'colvis',
                   text: "Colonne",
                  columns: ':not(.noVis)'},
                  { extend: 'create',
                   text: "Nuovo",
                   editor: editor },
                  { extend: 'edit',
                   text: "Modifica",
                   editor: editor },             
                  { extend: "remove",
                   text: "Rimuovi",
                   editor: editor,
                      formMessage: function ( e, dt ) {
                          var rows = dt.rows( e.modifier() ).data().pluck('pignoramenti.field1');
                          return 'Eliminare il record relativo al soggetto'+rows.join+' ?';}
                      },
                  { extend: 'collection',
                      text: 'Esporta',
                          buttons: [
                              'excel',
                              'csv',
                              'pdf',
                              'print'
                                      ]
                      }
                  ],
                  } );

Tabletwo = new $.fn.dataTable.Editor
 $('#table2').DataTable( {
  dom: 'Bfrtip',
     "bProcessing": true,
     "bServerSide": true,
ajax: "../php/Anag.php",
     "scrollX": true,
columns: [
  { data: "table2.id" },
  { data: "tabel2.field2" },
  { data: "tabel2.field3" },
  { data: "tabel2.field4" },
              ],
      fixedColumns: true,
select: true,
buttons: [
  { extend: 'create', editor: editor },
  { extend: 'edit',   editor: editor },
  { extend: "remove", editor: editor,
          formMessage: function ( e, dt ) {
          var rows = dt.rows( e.modifier() ).data().pluck('table2.id');
          return 'Eliminare il record relativo al soggetto'+rows.join+' ?';}
   },
   {
      extend: 'collection',
      text: 'Export',
      buttons: [
          'excel',
          'csv',
          'pdf',
          'print'
      ]
  }
]
  } );
} );

staff.php

enter code here

<?php
include( "../../php/DataTables.php" );

use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate;

Editor::inst( $db, 'table1' )
->fields(
 Field::inst( 'table1.field1' ),
 Field::inst( 'table1.field2' )->validator( 'Validate::notEmpty' ),
 Field::inst( 'table1.field3' )
    ->validator( 'Validate::dateFormat_required', 'Y-m-d' )
    ->getFormatter( 'Format::date_sql_to_format', 'Y-m-d' )
    ->setFormatter( 'Format::date_format_to_sql', 'Y-m-d' ),
 Field::inst( 'table1.field4' ),
 Field::inst( 'table1.field5' )
     ->setFormatter( 'Format::fromDecimalChar')->setFormatter('Format::ifEmpty', 0 ),  
 ->process( $_POST )
 ->json();

Anag.php

<?php
include( "../../php/DataTables.php" );

use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate;

Editor::inst( $db, 'table2' )
 ->fields(
 Field::inst( 'table2.id' ),
 Field::inst( 'tabel2.field2' )->validator( 'Validate::notEmpty' ),
 Field::inst( 'tabel2.field3' ),
 Field::inst( 'tabel2.field4' ) 
->process( $_POST )
->json();

非常感谢。

0 个答案:

没有答案