Inline editing primary key column / DT_RowId updated

Inline editing primary key column / DT_RowId updated

fmeyer@nearbysoftware.comfmeyer@nearbysoftware.com Posts: 18Questions: 5Answers: 0

Hello,

In a project of mine, I have several DataTables working flawlessly including heavy usage of Editor.

For a very specific use case I need for one DataTable to let the user be able to edit the "primary key" column as well, for any row.

From the information that is posted I can update the database table successfully, but then I return an object with an updated generated DT_RowId... which seems to confuse DataTable as it is not the same as the one that was sent initially.

So the result is that, after the submit, the edited row just disappears from the DataTable (like if it has been deleted).
Only if I reload the whole page, would the DataTable reload all the correct information including the updated row.

I tried invalidating the rows cached metadata on several events (postSubmit, postEdit, ...), and many other options to no available. Looking further in the data object of the relevant DataTable, it only contains the unchanged rows, meaning the new row has indeed not been saved.

Is there any way to make this work?

Thanks

Replies

  • fmeyer@nearbysoftware.comfmeyer@nearbysoftware.com Posts: 18Questions: 5Answers: 0

    Ok so a workaround was to issue an table.DataTable().ajax.reload() in a postSubmit event when the primary key was successfully detected as changed (to optimize and not to reload on every operations).

    If anyone has a better solution, please share.

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

    Interesting - the server-side libraries do handle this correctly, but it would appear the client-side libraries don't. As you say, the change in ID means the original row is deleted (since it no longer "exists"), while the new row (new id) doesn't get created.

    I think that's a bug in Editor - it should create the new row.

    I'll look into fixing that for the next release. Until then, your current solution is correct.

    Allan

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

    I've just committed the required change to Editor, which will be included in Editor 1.5.5 which I expect to be released at the end of the month.

    Until then, you could use your existing workaround, or if you want to apply the fix to your local Editor copy, search the code for the following comment:

                    // Remove the item from the list of indexes now that is has been
                    // updated
    

    Then replace the if block that contains it with:

                if ( row.any() ) {
                    row.data( data );
    
                    // Remove the item from the list of indexes now that is has been
                    // updated
                    var idx = $.inArray( rowId, store.rowIds );
                    store.rowIds.splice( idx, 1 );
                }
                else {
                    // If not found, then its a new row (change in pkey possibly)
                    row = dt.row.add( data );
                }
    
                __dtHighlight( row.node() );
    

    Regards,
    Allan

  • fmeyer@nearbysoftware.comfmeyer@nearbysoftware.com Posts: 18Questions: 5Answers: 0

    Oh! I'm seeing this only now... was expecting to be notified by mail if someone happened to reply but didn't receive any (neither in Junk). Any reason why?

    Anyway, thanks Allan for acknowledging this and fixing it!

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

    It will depend upon your forum settings, which you can access by clicking your user name above.

    Allan

This discussion has been closed.