A new row with empty values

A new row with empty values

andreavelloneandreavellone Posts: 46Questions: 13Answers: 2

Hi everybody,
i insert new row and i edit it inline. And everything is ok...

http://temisgest.it/tg/files/inline/temis-ol.php

But, I'd like to have a new row with empty value and for example for the date the new row put the today date, or for the number for default in the new row I have a 0.

Some Ideas?

here the debug: http://debug.datatables.net/ejoxul
**Here the server side code:

<?php

/*
 * Example PHP implementation used for the index.html example
 */

// DataTables PHP library
include( "../../php/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;
    
    // Allow a number of different formats to be submitted for the various demos
$format = isset( $_GET['format'] ) ?
    $_GET['format'] :
    '';
 
if ( $format === 'custom' ) {
    $update = 'n/j/Y';
    $registered = 'l j F Y';
}
else {
    $update = Format::DATE_ISO_8601;
    $registered = Format::DATE_ISO_8601;
}

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'ol' )
    ->fields(
        
        Field::inst( 'ol.ol' ),
        Field::inst( 'ol.fase' ),
        Field::inst( 'ol.centrale' ),
        Field::inst( 'ol.Data_Inizio' )
        ->validator( 'Validate::dateFormat', array(
                'empty' => false,
                'format' => $update
            ) )
            ->getFormatter( 'Format::date_sql_to_format', $update )
            ->setFormatter( 'Format::date_format_to_sql', $update ),
        Field::inst( 'ol.Data_Fine' )
        ->validator( 'Validate::dateFormat', array(
                'empty' => false,
                'format' => $update
            ) )
            ->getFormatter( 'Format::date_sql_to_format', $update )
            ->setFormatter( 'Format::date_format_to_sql', $update ),
        Field::inst( 'ol.cliente_id' )
        ->options( Options::inst()
                ->table( 'clienti' )
                ->value( 'id' )
                ->label( 'nome' )
            )
        ->validator( 'Validate::dbValues' ),
        Field::inst( 'clienti.nome' ),
        Field::inst( 'ol.fatturato' )
        ->setFormatter( function ( $val, $data, $opts ) {
                return ! $val ? 0 : 1;
            } ),
        
        Field::inst( 'ol.Materiali_id' ),
        Field::inst( 'ol.costi_materiali' ),
        Field::inst( 'ol.impiegati_id' ),
        Field::inst( 'ol.Time_Stamp' )
        
      )
    ->leftJoin('clienti', 'clienti.id', '=' , 'ol.cliente_id') 
    ->process( $_POST )
    ->json();

<?php
>
```
**This is the + button:
**
```
?>


                buttons: [
        
        {
                    extend: "create",
                    text:"+",
                    editor: editor,
                    className: 'btn btn-success waves-effect waves-light m-r-5',
                    action: function (e, dt, node, config) {
 
                        //var id = $("#id").val();
                       // var DebtorId = $('#SearchDebtorInvoice').data('debtorId');
 
                        editor
                                .create(false)
                                
                                .set('ol.ol')
                                .set('ol.fase')
                                .set('ol.centrale')
                                .set('ol.Data_Inizio')
                                .set('ol.Data_Fine')
                                .set('ol.cliente_id')
                                .set('ol.fatturato')
                                .set('ol.Materiali_id')
                                .set('ol.costi_materiali')
                                .set('ol.impiegati_id')
                                

                                .submit();
 
        

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi,

    Do you mean you want the new row to be completely empty of all values, but as you inline edit it, the defaults will be sensible (i.e. today for the date columns)? I'm sorry to say that is not something that Editor supports at this time. In order to be able to inline edit, the data needs to exist in the database (its inline edit, not inline create) and the database will likely require values for columns such as the date columns and any others which have a default value set in the schema.

    Allan

  • andreavelloneandreavellone Posts: 46Questions: 13Answers: 2

    Thanks a lot Allan,
    you're doing a great job :)

This discussion has been closed.