Ajax DataSrc

Ajax DataSrc

bill_Tombill_Tom Posts: 19Questions: 4Answers: 0
edited October 2015 in Free community support

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

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    Please reformat your post.

  • bill_Tombill_Tom Posts: 19Questions: 4Answers: 0
    edited October 2015

    reformated

  • allanallan Posts: 63,356Questions: 1Answers: 10,447 Site admin
    Answer ✓

    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.:

    ajax: "php/table.gehalt.php?table=gehalt_1",
    

    Then in your PHP you can simply do:

    if ( $_GET['table'] === 'gehalt_1' ) {
      Editor::inst( ... )
    }
    

    You will also need to add that GET parameter to the Editor ajax URL - otherwise the edit won't work!

    Allan

  • bill_Tombill_Tom Posts: 19Questions: 4Answers: 0

    Hi Allan,
    sometimes it is so....

    I tried this code yesterday and it doesn't work... Semantics mistake...

    Thanks a lot!!!
    Thomas

This discussion has been closed.