New records not showing up using editor extension

New records not showing up using editor extension

wallinwallin Posts: 4Questions: 1Answers: 0

Hello,

we are evaluating the editor extension, but we have a problem with the creation of new records.

The new record is correctly saved into the database but it does not show up in the table, we need to reload the page to see it.

We are using only the javascript part of the plugin, here the json response from server to client:

{"data":[{"Id":"62f12a22-001a-4496-8d18-ff2985544a47","Address":"987","PhoneNumber":"987","Notes":"987","Shift":0}]}

Here's the debugger result:

https://debug.datatables.net/onaril

On side note, we have tried the editor server plugin too, (.NET) and the result is exactly the same, the record is created on db but it do not show up in the table.

Thank you in advance.

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Are you seeing any error message(s)?

  • wallinwallin Posts: 4Questions: 1Answers: 0

    No, forgot to specify, we don't have any error message.

    If we force the reload like this

    editor.on('submitSuccess', () => {
            $('#tableId').DataTable().ajax.reload();
    });
    

    we see the new record, but I don't think this should be the normal behaviour.

    Am I wrong?

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28

    Does the response JSON to the editor ajax call match your Editor setting in regards to dataSrc / root object?

  • wallinwallin Posts: 4Questions: 1Answers: 0

    I wasn't, but I fixed it now. Sadly the result is the same, the new record is not showing.

    Here's the setup code of the table

    $(document).ready(function () {
                var editor = new $.fn.dataTable.Editor({
                    ajax: '/PharmaShift/Pharmacy',
                    fields: [
                        {
                            label: 'Address:',
                            name: 'Address'
                        },
                        {
                            label: 'PhoneNumber:',
                            name: 'PhoneNumber'
                        },
                        {
                            label: 'Notes:',
                            name: 'Notes'
                        },
                        {
                            label: 'Shift:',
                            name: 'Shift'
                        }
                    ]
                });
    
                $('#pharmacies').DataTable({
                    ajax: {
                        url: '/PharmaShift/Pharmacies'
                    },
                    dom: 'Bfrtip',
                    columns: [
                        { data: 'Address' },
                        { data: 'PhoneNumber' },
                        { data: 'Notes' },
                        { data: 'Shift' }
                    ],
                    select: true,
                    buttons: [
                        { extend: 'create', editor: editor },
                        { extend: 'edit', editor: editor },
                        { extend: 'remove', editor: editor },
    
                    ]
                });
            });
    

    This is an example of the json source of the datatable (and it works)

    {  
       "data":[  
          {  
             "DT_RowId":"072d349e-e668-47bb-9b8f-de195f20b8d6",
             "Address":"zzz",
             "PhoneNumber":"zzz",
             "Notes":"zzz",
             "Shift":1
          },
          {  
             "DT_RowId":"0e819681-a3ce-45e2-875a-054fcd051f90",
             "Address":"www",
             "PhoneNumber":"www",
             "Notes":"www",
             "Shift":1
          }
       ]
    }
    
    

    This is the json response to the editor create (the record is created on database, but doesn't show up in the datatable)

    {  
       "data":[  
          {  
             "DT_RowId":"63abe340-59cf-4595-ac88-98ba4b443c60",
             "Address":"yyy",
             "PhoneNumber":"yyy",
             "Notes":"yyy",
             "Shift":0
          }
       ]
    }
    
    

    And the datatable debugger result updated:

    https://debug.datatables.net/ilefed

    and no error in console.

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28
    edited July 2017 Answer ✓

    Ah ha, got it. You're missing the table config option on the Editor options. Editor doesn't know what table to work on. See table

    Working example: http://live.datatables.net/cinazabo/3/edit

    Note, I replaced your ajax urls with DT/Editor function versions so i could simulate an ajax call. The important thing is the table (line 4) option on the editor configuration that shows a row will be created. Adding the table option to your code is all you need to do.

  • wallinwallin Posts: 4Questions: 1Answers: 0

    That was it, thank you very much for your help and for the very detailed example!

This discussion has been closed.