Problem with JS

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,144Questions: 1Answers: 2,586
    Answer ✓

    They appear to be working for me. Can you elaborate on the problem you're seeing, please?

    Colin

  • equintanilla82equintanilla82 Posts: 9Questions: 2Answers: 0

    Thank you Collin, I thought it was those links.

    I am totally new. I am learning some PHP programming but to tell you the truth, I download an example to understand how to build the code to use the Editor.

    The link is: https://eldesvandejose.com/2016/12/07/el-editor-de-datatables-ii-funcionamiento-basico/

    The problem is that the code in that example does not launch the action in the buttons: Edit - New - Delete.

    I thought the problem was those links.

    I have no idea where to download a complete example with the editor. The examples on the official webpage are too hard to follow. I do not know where to paste the code they mention. I do not know if all the examples has to be in one php file, or how to structure the folder with one or several php files.

    Do you know a website to download a complete example?

    Thank you in advance!
    Eduardo

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    The link is: https://eldesvandejose.com/2016/12/07/el-editor-de-datatables-ii-funcionamiento-basico/
    The problem is that the code in that example does not launch the action in the buttons: Edit - New - Delete.

    Have you tried referring the problem to the author of that tutorial?

  • equintanilla82equintanilla82 Posts: 9Questions: 2Answers: 0

    Thank you Tangerine for your comment.
    Yes I tried, but it seems really old the website. Since 2016!! The last comment was last year in January.

    If I just have a complete example of editor with two relation-tables will be great!

    I used the generator, but it only allows the data of one table :(

  • colincolin Posts: 15,144Questions: 1Answers: 2,586
    Answer ✓

    As tangerine said, if you want support on that document, you'll need to speak to the author.

    We have a manual with installation instructions, which also talks about joins, and in-depth reference pages with examples.

    I'd say look at those, see how you go, and if no success, please report back and we'll see if we can help you,

    Colin

  • equintanilla82equintanilla82 Posts: 9Questions: 2Answers: 0
    edited November 2020

    Thank you Colin for your answer. I decided to start from scratch with my own code, because the author of my last question is not answering my questions.

    I used the generator to create an example and start joining tables.

    Now I am trying to follow your instructions on the "examples" page, but I am stock.

    Could you please take a look of my database and code?
    I am lost in the last file "Server script".

    DATABASE:

    JAVASCRIPT CODE:

    (function($){
    
    $(document).ready(function() {
        var editor = new $.fn.dataTable.Editor( {
            ajax: 'php/table.Proyectos.php',
            table: '#Proyectos',
            fields: [
                {
                    "label": "nombredelproyecto:",
                    "name": "Proyectos.nombredelproyecto"
                },
                {
                    "label": "estatus:",
                    "name": "Proyectos.id_estatus"
                },
                {
                    "label": "nombregenerico:",
                    "name": "Proyectos.nombregenerico"
                },
                {
                    "label": "formafarmaceutica:",
                    "name": "Proyectos.formafarmaceutica"
                },
                {
                    "label": "fechainicio:",
                    "name": "Proyectos.fechainicio",
                    "type": "datetime",
                    "format": "ddd, D MMM YY"
                }
            ]
        } );
    
        var table = $('#Proyectos').DataTable( {
            dom: 'Bfrtip',
            ajax: {
                url: "php/table.Proyectos.php",
                type: 'POST'
            },
            columns: [
                {
                    "data": "Proyectos.nombredelproyecto"
                },
                {
                    "data": "Estatus.estatus"
                },
                {
                    "data": "Proyectos.nombregenerico"
                },
                {
                    "data": "Proyectos.formafarmaceutica"
                },
                {
                    "data": "Proyectos.fechainicio"
                }
            ],
            select: true,
            lengthChange: false,
            buttons: [
                { extend: 'create', editor: editor },
                { extend: 'edit',   editor: editor },
                { extend: 'remove', editor: editor }
            ]
        } );
    } );
    

    }(jQuery));

    SERVER SCRIPT:

    <?php
    
    // DataTables PHP library and database connection
    include( "lib/DataTables.php" );
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;
    
    
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'Proyectos', 'id')
        ->fields(
            Field::inst( 'Proyectos.nombredelproyecto' ),
            Field::inst( 'Proyectos.id_estatus' )
                ->options( Options::inst()
                    ->table( 'Estatus' )
                    ->value( 'id' )
                    ->label( 'estatus' )
                ),
                ->validator( Validate::dbValues() )
                Field::inst( 'Estatus.estatus' ),   
            Field::inst( 'Proyectos.nombregenerico' ),
            Field::inst( 'Proyectos.formafarmaceutica' ),
            Field::inst( 'Proyectos.fechainicio' )
                ->validator( Validate::dateFormat( 'D, j M y' ) )
                ->getFormatter( Format::dateSqlToFormat( 'D, j M y' ) )
                ->setFormatter( Format::dateFormatToSql( 'D, j M y' ) )
        )
        ->leftJoin( 'Estatus', 'id', '=', 'Proyectos.id_estatus' )
        ->process( $_POST )
        ->json();
    
    
    

    Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    When you say you're stuck, what's the problem? Are you seeing errors?

    Colin

  • equintanilla82equintanilla82 Posts: 9Questions: 2Answers: 0

    Hi Collin, you are very kind.
    The error says:
    DataTables warning: table id=Proyectos - Ajax error. For more information about this error, please see http://datatables.net/tn/7

    I ran the instructions of the Help-page and this appears:

  • colincolin Posts: 15,144Questions: 1Answers: 2,586
    Answer ✓

    The link in the error code is the place to start. It'll suggest diagnostic steps to try.

    Colin

  • equintanilla82equintanilla82 Posts: 9Questions: 2Answers: 0

    Dear Colin, I did it!! Thank you for your advice!!

This discussion has been closed.