How do I manually edit data after a postSubmit event?

How do I manually edit data after a postSubmit event?

MeyerSoundMeyerSound Posts: 3Questions: 1Answers: 0

Hello,

I have a situation where I want to edit some data in my DataTable in a postSubmit() event, particularly when handling a 'remove' action and getting an error message back. I want to 'manually' edit some of the data in the row being edited but am having trouble with the syntax of doing so.

Here's my postSubmit handler - when it encounters the 'error' case, I get the row editing dialog box for some reason.

editor.on( 'postSubmit', function ( e, json, data, action ) {
    if (action === 'remove') {
        if (json.error) {
            console.log('got error '+json.error)
            editor
                .edit(table.row( { selected: true } ).index(), false)
                .set(5, '')
        }
    }
})

Note that i'm using .set(5, '') because my table data doesn't have column names.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,818Questions: 1Answers: 10,517 Site admin

    Use submitComplete rather than postSubmit for this. The issue with postSubmit is that Editor is still processing the previous submit, when it is then being instructed to go and do another one. Currently and Editor instance can only handle one request at a time.

    Another way of doing this (possibly a better one) is to use a second Editor instance for the secondary edit.

    Regards,
    Allan

  • MeyerSoundMeyerSound Posts: 3Questions: 1Answers: 0

    Thanks Allan - in the end I decided that my use case was a little more conceptually complex than I thought so I made a custom button that calls editor.remove in some cases and editor.edit in others.

    I'm still curious though, maybe more for the benefit of others who read this, what the best practice would be for handling non-interactive data changes. In this case, say I were to use submitComplete and wanted to change the data for the fifth column of the row I had edited from 'foo' to 'bar' without prompting the user. Better to use an editor instance or should could I used the data table API to make the change?

  • allanallan Posts: 63,818Questions: 1Answers: 10,517 Site admin
    Answer ✓

    Better to use an editor instance or should could I used the data table API to make the change?

    If you want a permanent change (i.e. written to the database), use Editor (which in turn also updates the DataTable). If you need a non-permanent change (i.e. local only) use the DataTables API.

    Allan

  • MeyerSoundMeyerSound Posts: 3Questions: 1Answers: 0

    Thanks!

This discussion has been closed.