Dt_RowId are all the same in postSubmit?

Dt_RowId are all the same in postSubmit?

daanbonkedaanbonke Posts: 7Questions: 5Answers: 0
edited December 2015 in DataTables 1.10

Hi,

I'm having a strange issue here.
I'm using datatables editor and I'm requesting this JSON:

{
    "data": [{
                "DT_RowId": "row_735",
                "afschrijvingen": {
                    "afschrijvingen_id": "735",
                    "indentificatienummer": "19338",
                    "investeringsjaar": "2014",
                    "investeringsmaand": "5",
                    "omschrijving": "Koelkast LIEBHERR UKS 3600",
                    "investeringsbedrag": "875.00",
                    "afschrijvingstermijn": "10",
                    "kostenplaats_id": "419",
                    "jaar_buiten_gebruik": null,
                    "maand_buiten_gebruik": null
                },
                "kostenplaatsen": {
                    "kostenplaats_omschrijving": "U-AFNAME KLINIEK"
                }
            }, {
                "DT_RowId": "row_736",
                "afschrijvingen": {
                    "afschrijvingen_id": "736",
                    "indentificatienummer": "19339",
                    "investeringsjaar": "2014",
                    "investeringsmaand": "5",
                    "omschrijving": "Koelkast LIEBHERR UKS 1800",
                    "investeringsbedrag": "736.00",
                    "afschrijvingstermijn": "10",
                    "kostenplaats_id": "419",
                    "jaar_buiten_gebruik": null,
                    "maand_buiten_gebruik": null
                },
                "kostenplaatsen": {
                    "kostenplaats_omschrijving": "U-AFNAME KLINIEK"
                }
            }, {
                "DT_RowId": "row_737",
                "afschrijvingen": {
                    "afschrijvingen_id": "737",
                    "indentificatienummer": "29397",
                    "investeringsjaar": "2014",
                    "investeringsmaand": "11",
                    "omschrijving": "Afslag Apparaat Kramers 3708e",
                    "investeringsbedrag": "2215.00",
                    "afschrijvingstermijn": "10",
                    "kostenplaats_id": "419",
                    "jaar_buiten_gebruik": null,
                    "maand_buiten_gebruik": null
                },
                "kostenplaatsen": {
                    "kostenplaats_omschrijving": "U-AFNAME KLINIEK"
                }
            }, {
                "DT_RowId": "row_738",
                "afschrijvingen": {
                    "afschrijvingen_id": "738",
                    "indentificatienummer": "29449",
                    "investeringsjaar": "2014",
                    "investeringsmaand": "4",
                    "omschrijving": "Afslag Apparaat Kramers

It's a lot bigger in real.

Now when open chrome's inspector I can see:

<tr id="row735"></tr>
<tr id="row736"></tr>
<tr id="row737"></tr>
<tr id="row738"></tr>

But now when I edit a record (inline) it ALWAYS returns Dt_RowId = 735 in the console.log by postSubmit

    editorproductiemiddelen = new $.fn.dataTable.Editor( {
        ajax: "brondata/ajax/productiemiddelen.php",
        table: "#productiemiddelen_table",
        fields: [ {
                    label: "Identificatienummer:",
                    name: "afschrijvingen.indentificatienummer"                 
                  },
                  {
                    label: "Investeringsjaar:",
                    name: "afschrijvingen.investeringsjaar" 
                  },
                  {
                    label: "Investeringsmaand:",
                    name: "afschrijvingen.investeringsmaand"
                  },
                  {
                    label: "Omschrijving:",
                    name: "afschrijvingen.omschrijving"
                  },
                  {
                    label: "Investeringsbedrag",
                    name: "afschrijvingen.investeringsbedrag"
                  },
                  {
                    label: "Afschrijvingstermijn",
                    name: "afschrijvingen.afschrijvingstermijn"
                  },
                  {
                    label: "Kostenplaats:",
                    name: "afschrijvingen.kostenplaats_id",
                    type: "select"                  
                  },  
                  {
                    label: "Jaar buiten gebruikstelling:",
                    name: "afschrijvingen.jaar_buiten_gebruik"
                  },
                  {
                    label: "Maand buiten gebruikstelling:",
                    name: "afschrijvingen.maand_buiten_gebruik"
                  }
        ],
        i18n: {
            create: {
                button: "Toevoegen",
                title:  "Record toevoegen",
                submit: "Toevoegen"
            },
            edit: {
                button: "Wijzigen",
                title:  "Record wijzigen",
                submit: "Wijzigen"
            },
            remove: {
                button: "Verwijderen",
                title:  "Record Verwijderen",
                submit: "Verwijderen",
                confirm: {
                    _: "Weet u zeker dat u %d records wilt verwijderen?",
                    1: "Weet u zeker dat u dit record wilt verwijderen?"
                }
            },
            error: {
                system: "Er is een fout opgetreden, neem a.u.b. contact op met Bonke Web-IT"
            }
        }
    } );

    var editorProductiemiddelenSubmit = false;
     
    editorproductiemiddelen
        .on( 'open', function ( e, type ) {
            if ( type === 'inline' ) {
                // Listen for a tab key event when inline editing
                $(document).on( 'keydown.editorproductiemiddelen', function ( e ) {
                    if ( e.keyCode === 9 ) {
                        e.preventDefault();
 
                        // Find the cell that is currently being edited
                        var cell = $('div.DTE').parent();
 
                        if ( e.shiftKey && cell.prev().length && cell.prev().index() !== 0 ) {
                            // One cell to the left (skipping the first column)
                            cell.prev().click();
                        }
                        else if ( e.shiftKey ) {
                            // Up to the previous row
                            cell.parent().prev().children().last(0).click();
                        }
                        else if ( cell.next().length ) {
                            // One cell to the right
                            cell.next().click();
                        }
                        else {
                            // Down to the next row
                            cell.parent().next().children().eq(1).click();
                        }
                    }
                } );
            }
        } )
        .on( 'close', function () {
            $(document).off( 'keydown.editorproductiemiddelen' );
        } )
        .on ( 'postSubmit', function(data, row, info) {     
            if(info.action == 'edit'){      
                if(typeof $(row)[0].row !== 'undefined'){
                    var id = $(row)[0].row.DT_RowId; // THIS IS ALWAYS row_735

                    console.log(row);  /// HERE 
   
                    $.ajax({
                        type: 'POST',
                        url: '/brondata/ajax/productiemiddelen_update.php',
                        data: { 'type': 'update', 'rowID': id }
                    }).done(function(response){
                        
                    });     
                }
            }
        } );

Unfortuntely I don't have an URL in which I can show you.
I'm using datatables 1.10.6.

Hopefully some can help me.

Answers

  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin

    Could you update your DataTables 1.10.10 in the first instance please.

    Also, how are you triggering the inline editing?

    Allan

  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin

    .on ( 'postSubmit', function(data, row, info) {

    This doesn't look right to me. The documentation for postSubmit as the event handler signature as:

    function( e, json, data, action )

    Your row parameter is in fact the JSON data being returns from the server - r at least it should be!

    Allan

  • daanbonkedaanbonke Posts: 7Questions: 5Answers: 0
    edited December 2015

    Well this works perfectly, and it returns the data it should:

     .on ( 'postSubmit', function(data, row, info) {
    

    And it defintely doesn't return the JSON from the server.

    This is how I trigger it:

    $('#productiemiddelen_table').on( 'click', 'tbody td:not(:first-child)', function (e) {
        editorproductiemiddelen.inline( this, {
            submitOnBlur: true
        } );
    } );
    

    Can I update datatables to the newest version and will everything work (no big changes)?

  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin

    Update notes are here.

    I'm afraid I don't understand why that event works at all. Can you link to the page so I can take a look please?

    Allan

This discussion has been closed.