Intervals Editor for Datatables editor jquery.

Intervals Editor for Datatables editor jquery.

defdogdefdog Posts: 8Questions: 3Answers: 0

i have a field which represents a delay time in seconds. i want to edit it as hours minutes seconds with something like datetimepicker - any ideas. The formatting of static display is easy,

/*
 * Editor client script for DB table detention_rules
 * Created by http://editor.datatables.net/generator
 */

(function($){
    function sec2intvl( data, type, full, meta ) {
        var secs = parseInt(data);
        var hours = Math.floor(secs / 3600);
        var r = secs - (hours * 3600);
        var rmin = Math.floor(r / 60); 
        var rsec = r - (rmin * 60);
        
        var a = ("0" + hours);
        var ret = a.substr(a.length - 2, 2) +':' ;
        a = ("0" + rmin);
        ret += a.substr(a.length - 2, 2) +':';
        a = ("0" + rsec);
        ret += a.substr(a.length - 2, 2);

        return (ret);
        }

$(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
        ajax: 'js/DataTablesEditor/php/table.detention_rules.php',
        table: '#detention_rules',
        fields: [
            {
                "label": "ID",
                "name": "detention_rules.detention_rule_id",
                "type": "readonly"
            },
            { "label": "Name", "name": "detention_rules.rule_name" },
            { "label": "Grace Time", "name": "detention_rules.grace_sec" },
        ]
    } );


    var table = $('#detention_rules').DataTable( {
        dom: 'Bfrtip',
        ajax: 'js/DataTablesEditor/php/table.detention_rules.php',
        columnDefs: [ { targets: [ 0 ], visible:false }, ],
        columns: [
            { "data": "detention_rules.detention_rule_id" },
            { "data": "detention_rules.rule_name" },
            { "data": "detention_rules.grace_sec", "render" : sec2intvl},
        ],
        select: true,
        lengthChange: false,
        buttons: [
            { extend: 'create', editor: editor },
            { extend: 'remove', editor: editor }
        ]
    } );

    $('#detention_rules').on( 'click', 'tbody td', function (e) {
        editor.inline( this, {
            submit: 'changed',
            submitOnBlur: 'true'
        } );
    } );

} );

}(jQuery));

php is:

<?php

/*
 * Editor server script for DB table DetentionTables
 * Created by http://editor.datatables.net/generator
 */

// 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\Upload,
    DataTables\Editor\Validate;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'detention_rules', 'detention_rule_id' )
    ->fields(Field::inst( 'detention_rules.detention_rule_id' )
            ,Field::inst( 'detention_rules.rule_name' )
            ,Field::inst( 'detention_rules.grace_sec' )
            )
    ->process( $_POST )
    ->json();


This discussion has been closed.