Ajax DataSrc
Ajax DataSrc
bill_Tom
Posts: 19Questions: 4Answers: 0
Hello,
i have a lot of PHP Files where my Editor is build in.
Now I want only one PHP File for all of my Editors.
I call them about ajax...
JS-File:
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: { "url": "php/table.gehalt_1.php",
"dataSrc": "demo_1"
} ,
table: '#gehalt_1',
fields: [.........
PHP-File:
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
demo_1: {
Editor::inst( $db, 'gehalt_1', 'id' )
->fields(
Field::inst( 'sql_name' ),
Field::inst( 'sql_adresse' ),
Field::inst( 'sql_gehalt' ),
Field::inst( 'sql_geschlecht' ),
Field::inst( 'sql_datum' )
->validator( 'Validate::dateFormat', array( 'format'=>'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( 'sql_alter' )
->validator( 'Validate::numeric' )
)
->process( $_POST )
->json() ;
}
demo_2: {
Editor::inst( $db, 'gehalt_1', 'id' )
->fields(
Field::inst( 'sql_name' ),
Field::inst( 'sql_adresse' ),
Field::inst( 'sql_gehalt' ),
Field::inst( 'sql_geschlecht' ),
Field::inst( 'sql_datum' )
->validator( 'Validate::dateFormat', array( 'format'=>'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( 'sql_alter' )
->validator( 'Validate::numeric' )
)
->process( $_POST )
->json() ;
}
I tried a lot, but nothing worked... I think there must be a way, that i can use only one php-file for all of my ajax (dataSrc) request.
Can somebody help me or post en example.
Thx a lot..
Thomas
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Please reformat your post.
reformated
Hi,
Thanks for your question. What I would suggest you do is pass a parameter to the server to indicate which table should be used - don't use
ajax.dataSrc
, but just add a GET parameter to identify the table - e.g.:Then in your PHP you can simply do:
You will also need to add that GET parameter to the Editor
ajax
URL - otherwise the edit won't work!Allan
Hi Allan,
sometimes it is so....
I tried this code yesterday and it doesn't work... Semantics mistake...
Thanks a lot!!!
Thomas