Edit don't return anything, but update database correctly...?

Edit don't return anything, but update database correctly...?

ztevieztevie Posts: 101Questions: 23Answers: 5
edited January 2017 in Free community support

I have a table that loads as it should. However, when edit a row, nothing is returned in "data" and the row disappears from the table. When I reload the table the row shows again and with the correct edited fields, so it does update the database as expected.
EDIT: No, it doesn't update the database now. It did before but I must have done something when trying to find the problem... :(
I also notice when doing "remove" the row disappears from the table but not from the database, so when reloading it appears as in the initial load.
I have a feeling it has something to do with my own mistake, but can't figure out what...
Worth mentioning maybe that this is a table #2 on my page, so this table is loaded depending on what row a user choose in table #1. But I renamed everything so there shouldn't be a conflict. They also call different php-pages...
I also tested to put an alert on preEdit and postEdit of this editor but they never fire.

<?php
 
// 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\Upload,
    DataTables\Editor\Validate;
if(!isset($_POST['action'])){
    $blastid = $_GET['bid'];
}
else{
    $blastid = $_POST['bid'];
}
Editor::inst( $db, 'holes', 'hole_id' )
    ->field(
        Field::inst( 'holes.hole_nr' ),
        Field::inst( 'holes.hole_depth' ),
        Field::inst( 'holes.hole_drilled' ),
        Field::inst( 'holes.hole_boostered' ),
        Field::inst( 'holes.hole_kaxed' ),
        Field::inst( 'holes.hole_redrill' ),
        Field::inst( 'holes.blast_id' )
            ->set(false)
    )
    ->where('blast_id', $blastid)
    ->process($_POST)
    ->json();

<?php
>
```
```javascript
//Initialize table holes, depending on blastchoice
    $('#tbl-admin-blasts').on( 'click', 'a.holes', function () {
        bl_id = bTable.row($(this).closest('tr')).id().substring(4);
        var blast_name = bTable.cell( $(this).closest('tr'), 0 ).data();
        $("#holediv").removeClass("hidden");
        $(".holetitle").html("för salva " + blast_name + "");
        if(hTable !== null){
            hTable.destroy();
        };
        
        hTable = $('#tbl-admin-holes').DataTable( {
            language: {
                "url": "js/helpers/Swedish.json"
            },
            dom: 'B<"clear"><"hToolbar">rtlip',
            responsive: true,
            processing: true,
            ajax: {
                url: "../_includes/process_adminholes.php?bid=" + bl_id,
                type: 'POST'
            },
            order: [ 0, 'asc' ],
            columns: [
                { data: "holes.hole_nr", responsivePriority: 1 },
                { data: null,
                    render: function(data, type, row){
                            return parseFloat(data.holes.hole_depth).toFixed(1);
                    },
                    className: "dt-center",
                    responsivePriority: 2 
                },
                { data: null,
                    render: function(data, type, row){
                        if(type === 'display'){
                            if(data.holes.hole_drilled === "1"){
                                return '';
                            }
                            else{
                                return "";
                            }
                        }
                        else{
                            return data.holes.hole_drilled;
                        }
                    },
                    className: "dt-center",
                    responsivePriority: 3
                },
                { data: null,
                    render: function(data, type, row){
                        if(type === 'display'){
                            if(data.holes.hole_boostered === "1"){
                                return '';
                            }
                            else{
                                return "";
                            }
                        }
                        else{
                            return data.holes.hole_boostered;
                        }
                    },
                    className: "dt-center",
                    responsivePriority: 4
                },
                { data: null,
                    render: function(data, type, row){
                        if(type === 'display'){
                            if(data.holes.hole_kaxed === "1"){
                                return '';
                            }
                            else{
                                return "";
                            }
                        }
                        else{
                            return data.holes.hole_kaxed;
                        }
                    },
                    className: "dt-center",
                    responsivePriority: 5
                },
                { data: null,
                    render: function(data, type, row){
                        if(type === 'display'){
                            if(data.holes.hole_redrill === "1"){
                                return '';
                            }
                            else{
                                return "";
                            }
                        }
                        else{
                            return data.holes.hole_redrill;
                        }
                    },
                    className: "dt-center",
                    responsivePriority: 6
                },
                { data: null,
                defaultContent: '',
                className: "dt-center",
                orderable: false,
                responsivePriority: 2
            },
            { data: null,
                defaultContent: '',
                className: "dt-center",
                orderable: false,
                responsivePriority: 3
            }
            ],
                select: false,
                buttons: [
                    { extend: 'create',
                        editor: hEditorCreate,
                        text: ' Nytt hål',
                        formTitle: ' Skapa nytt hål',
                        formButtons: [{
                            label: ' Avbryt',
                            fn: function() { this.close(); }
                    },
                    ' Spara'
                    ]
                    },
                { extend: 'collection',
                    editor: hEditor,
                    text: ' Exportera',
                    autoClose: true,
                    buttons: [
                        { extend: 'copy', text: ' Kopiera' },
                        { extend: 'excel', text: ' Excel' },
                            { extend: 'csv', text: ' CSV' },
                        { extend: 'pdf', text: ' PDF' },
                        { extend: 'print', text: ' Skriv ut' }
                    ]
                }
            ]
        } );
    } );
?>


//editor for updating holes only
    hEditor = new $.fn.dataTable.Editor( {
        ajax: {url: "../_includes/process_adminblasts.php",
            data: function(d){
                return $.extend( {}, d, {
                bid: bl_id
            } );
            }
        },
        table: "#tbl-admin-holes",
        formOptions: {
            main: {
                submit: 'changed'
            }
        },
        fields: [ {
                "label": "Planerat djup:",
                "name": "holes.hole_depth"
            }, {
                label: "Borrad:",
                name:  "holes.hole_drilled",
                type:  "checkbox",
                options: [
                    {label: "", value: 1 }
                ],
                separator: '',
                unselectedValue: 0
            }, {
                label: "Boostrad:",
                name:  "holes.hole_boostered",
                type:  "checkbox",
                options: [
                    {label: "", value: 1 }
                ],
                separator: '',
                unselectedValue: 0
            }, {
                label: "Kaxad:",
                name:  "holes.hole_kaxed",
                type:  "checkbox",
                options: [
                    {label: "", value: 1 }
                ],
                separator: '',
                unselectedValue: 0
            }, {
                label: "Uppborrning:",
                name:  "holes.hole_redrill",
                type:  "checkbox",
                options: [
                    {label: "", value: 1 }
                ],
                separator: '',
                unselectedValue: 0
            }
        ]
    } );

This question has an accepted answers - jump to answer

Answers

  • ztevieztevie Posts: 101Questions: 23Answers: 5
    Answer ✓

    OK, forget it!!
    As usual, I'm error-searching for 2 hours, then write this question and 5 minutes after I find the problem...
    Just a stupid user-error!

  • DatacreateDatacreate Posts: 1Questions: 0Answers: 0

    I have the same problem what did you do

This discussion has been closed.