Use of whole row + inline create

Use of whole row + inline create

arnonrdparnonrdp Posts: 29Questions: 8Answers: 0
edited March 2021 in Free community support

Hey guys, I know it is very simple, but I am racking my brain on how to make this table work.

I need to use this type of table on a project for a client: https://editor.datatables.net/examples/inline-editing/fullRowCreate.html

But I can't even run it on localhost. Following the same sequence of the link, I have:
- main.js (tab: Javascript)
- index.html (tab: HTML)
- staff.php (tab: Server script)
- ajax.js (tab: Ajax load)

What should I do to run it localhost first? Is there any .zip of that example?

Thanks.

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    This is a new feature of Editor 2.0. Have you downloaded those files, or are you still using 1.x?

    Colin

  • arnonrdparnonrdp Posts: 29Questions: 8Answers: 0

    I already downloaded then. But when I am about to add a user, it occurs an error:

    So, I wonder if there is a working example with data.

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    What errors are you seeing in the console? And what happens if you click on the "more information" link? Are you able to link to your page so we can take a look,

    Colin

  • arnonrdparnonrdp Posts: 29Questions: 8Answers: 0
    edited March 2021

    Here is the console:

    And staff.php looks like this:

    <?php
    /*
     * Example PHP implementation used for the index.html example
     */
    
    // DataTables PHP library
    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, 'datatables_demo' )
        ->fields(
            Field::inst( 'first_name' )
                ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( 'A first name is required' ) 
                ) ),
            Field::inst( 'last_name' )
                ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( 'A last name is required' )  
                ) ),
            Field::inst( 'position' ),
            Field::inst( 'email' )
                ->validator( Validate::email( ValidateOptions::inst()
                    ->message( 'Please enter an e-mail address' )   
                ) ),
            Field::inst( 'office' ),
            Field::inst( 'extn' ),
            Field::inst( 'age' )
                ->validator( Validate::numeric() )
                ->setFormatter( Format::ifEmpty(null) ),
            Field::inst( 'salary' )
                ->validator( Validate::numeric() )
                ->setFormatter( Format::ifEmpty(null) ),
            Field::inst( 'start_date' )
                ->validator( Validate::dateFormat( 'Y-m-d' ) )
                ->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )
                ->setFormatter( Format::dateFormatToSql('Y-m-d' ) )
        )
        ->debug(true)
        ->process( $_POST )
        ->json();
    

    "More information" link redirects me to: https://www.datatables.net/manual/tech-notes/12

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    Ah - you are trying to run it from file:// which isn’t going to work - the browser will block all Ajax communication to your local file system for security reasons. You need to do it through a web-server (even if installed on your local computer).

    Allan

  • arnonrdparnonrdp Posts: 29Questions: 8Answers: 0

    Thanks Allan!

    I will try to run direct on my server.

This discussion has been closed.