Editor inline submitting data for rows that don't change

Editor inline submitting data for rows that don't change

dmckim1977dmckim1977 Posts: 6Questions: 2Answers: 0

In my editor code I have some fields that have datepickers or dropdown on them. When the ajax comes in it will send the value for the field I changed and a blank value for any row that has

"type": "date"

The problem is if I previously had a value in a datefield it will replace it with ''" when I edit any other field. Is there any way to stop datatables from submitting a field that hasn't changed? I have a validator that will remove any empty strings but then I can't "erase" any edits that were made either.

Here is an example of a response where I only edited the notes field.

action: edit
data[239178][method_sent]: 
data[239178][date_signed_invoice_returned]: 
data[239178][date_submitted]: 
data[239178][notes]:  I changed this field

Here is my full code.

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: {
             url: '/invoices/invoices/_id_/',
             type: 'PUT',
             headers: {'X-CSRFToken': '{{ csrf_token }}'},
            },
        "table": "#example",
        "idSrc":  'id',
        "fields": [

                {
                    "label": "Date sent for signature:",
                    "name": "date_sent_for_signature",
                    "type": "date",
                },
                {
                    "label": "Method Sent:",
                    "name": "method_sent",
                    "type": "select",
                    options: [
                    {label: "", value: ""},
                    {label: "SAL", value: "SAL"},
                    {label: "EMA", value: "EMA"}
                    ]
                },
                {
                    "label": "Person sent with invoice:",
                    "name": "person_sent_with_invoice",
                    "type": "select",
                    options: [
                        {label: "", value: ""},
                        {label: "astock", value: "astock"},
                        {label: "rguerra", value: "rguerra"},
                        {label: "kporras", value: "kporras"},
                        {label: "bsmith", value: "bsmith"},
                        {label: "lsanchez", value: "lsanchez"},
                        {label: "amadeiro", value: "amadeiro"},
                        {label: "jmoore", value: "jmoore"},
                    ]
                },
                {
                    "label": "Date invoice returned:",
                    "name": "date_signed_invoice_returned",
                    "type": "date",
                },
                {
                    "label": "Date submitted:",
                    "name": "date_submitted",
                    "type": "date",
                },
                {
                    "label": "Notes:",
                    "name": "notes"
                }
        ]
    } );

    // Activate an inline edit on click of a table cell
    $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
        editor.inline( this );
    } );

    $('#example').DataTable( {
        "dom": "Blfrtip",
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ],
        "order": [[0, 'desc' ]],
        "ajax": {
         url: '/invoices/api/unpaid_invoices/',
         dataSrc: '[]',
         processData: true,
            error: function (xhr, jqAjaxerror, thrown) {
                if (xhr.status == 403) {
                    top.location.href = '/accounts/login/';
                } else {
                    alert("Please contact Supper for support with this error information " + xhr.status + "  "+ thrown +". Please note the time and which item you were updating.");
                }
            //This tells dataTables editor that the update failed
                dtFailureCallback( jqAjaxerror );
            }
        },
        "columns": [
            { "data": "invoice_number" },
            { "data": "bill_name" },
            { "data": "ordered_by" },
            { "data": "job_type" },
            { "data": "well_name" },
            { "data": "contractor" },
            { "data": "creation_date"},
            { "data": "invoice_office_code" },
            { "data": "invoice_total", render: $.fn.dataTable.render.number( ',', '.', 0, '$' )  },
            { "data": "date_sent_for_signature" },
            { "data": "method_sent" },
            { "data": "person_sent_with_invoice" },
            { "data": "date_signed_invoice_returned" },
            { "data": "date_submitted" },
            { "data": "notes" },
        ],
        keys: {
            columns: ':not(:first-child)',
            editor:  editor
        },
        select: {
            style:    'os',
            selector: 'td:first-child'
        },
    } );
     } );

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    We need to figure out why Editor is submitting it as an empty value. There is a way to submit only changed values (submit in form-options), but that won't help here if the correct date is not being set as a value.

    Can you give me a link to your page so I can take a look and see what is happening?

    Thanks,
    Allan

  • asalveasalve Posts: 1Questions: 0Answers: 0

    Hi Allan,

    Any update on this issue? I am also facing the same problem.

    Thanks,
    Abhishek

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    No, we didn't get the link we requested. Can you link to your page please, or modify this test case to demonstrate the issue, and provide steps on how to reproduce, please.

    Colin

This discussion has been closed.