Inline edit field is clearing on tab of another field

Inline edit field is clearing on tab of another field

Nwilliams8162Nwilliams8162 Posts: 28Questions: 4Answers: 0

Whenever I edit one inline editor field and tab/click off, it clears out the previous fields value

function loadDatatable(data) {
        var editor; // use a global for the submit and return data rendering in the examples

        var tabledata = [];

        var copiedsolines = data.solines;
        if (copiedsolines.length > 0) {
            var copiedsocount = 0;
            for (var i = 0; i < copiedsolines.length; i++) {
                copiedsocount++
                
                var copiedItemFields = {
                    "DT_RowId": "rowsso_" + copiedsocount,
                };
                for (var s = 0; s < itemTableColumns.length; s++) {
                    if (itemTableColumns[s].data != null ) {
                        var dataField = itemTableColumns[s].data;
                        copiedItemFields[dataField] = copiedsolines[i][dataField]
                    }
                }
                tabledata.push(copiedItemFields)
            }
        }
    
        jQuery(document).ready(function() {
            editor = new $.fn.dataTable.Editor( {
                data: tabledata,
                table: "#example",
                fields: tableEditableFields,
                formOptions: {
                    inline: {
                        onBlur: 'submit'
                    }
                }
            } );
            
          // Activate the bubble editor on click of a table cell
          $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
              editor.inline( this );
          });
          
            var table = jQuery('#example').DataTable( {
                dom: "Bfrtip",
                responsive : false,
                searching: false,
                paging: false,
                data: tabledata,
                columns: itemTableColumns,
                order: [ 1, 'asc' ],
                keys: {
                    columns: ':not(:first-child)',
                    keys: [9],
                    editor: editor,
                    editOnFocus: true
                },
                select: {
                    style:    'os',
                    selector: 'td:first-child'
                },
                  drawCallback: function( settings ) {
                    var api = this.api();
                    var tableRows = api.rows({ page: 'current' }).data();
                    //AMPLIFY CUSTOM CODE
                    var palletcount = 0;
                    //END AMPLIFY CUSTOM CODE
                    var numFormat = $.fn.dataTable.render.number( '\,', '.', 2, '&#36;' ).display;
                    var amountColTotal = 0;
                    //AMPLIFY CUSTOM CODE
                    if (tableRows) {
                        //AMPLIFY CUSTOM CODE
                        palletcount = 0;
                        //END AMPLIFY CUSTOM CODE
                        for(var i = 0; i < tableRows.length; i++) {
                            var tpi = api.cell( ':eq('+i+')', 'custcol_sps_purchaseprice:name', { page: 'current' } ).data();
                            var rate = api.cell( ':eq('+i+')', 'rate:name', { page: 'current' } ).data();
                            var qty = api.cell( ':eq('+i+')', 'quantity:name', { page: 'current' } ).data();
                            var amountTotal = tpi.replace('&#36;', '') * 1 > 0 ? tpi.replace('&#36;', '') * qty : rate.replace('&#36;', '') * qty;
                            amountColTotal += amountTotal;
                            api.cell( ':eq('+i+')', 'rate:name', { page: 'current' } ).data(numFormat(rate.replace('&#36;', '')));
                            api.cell( ':eq('+i+')', 'amount:name', { page: 'current' } ).data(numFormat(amountTotal));
                            //AMPLIFY CUSTOM CODE
                            var perpallet = api.cell( ':eq('+i+')', 'custcol_cases_per_pallet:name', { page: 'current' } ).data();
                            palletcount += qty/perpallet;
                            if (tpi) {
                              api.cell( ':eq('+i+')', 'custcol_sps_purchaseprice:name', { page: 'current' } ).data(numFormat(tpi.replace('&#36;', '')))
                            }
                            //END AMPLIFY CUSTOM CODE
                        }
                    }

                    var intVal = function ( i ) {
                        return typeof i === 'string' ?
                            i.replace(/[\$,]/g, '')*1 :
                            typeof i === 'number' ?
                                i : 0;
                    };

                    var thetotal = api
                        .column('amount:name')
                        .data()
                        .reduce( function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0 );
                    

                        // Update footer
                     jQuery('.itemtabletotal').html(
                        '&#x24;' +amountColTotal.toFixed(2)
                    );
                    //AMPLIFY CUSTOM CODE
                    jQuery('.tabletotalpallets').html(
                          palletcount.toFixed(2)
                      );
                    //END AMPLIFY CUSTOM CODE
                    
                }
            });
            //AMPLIFY CUSTOM CODE
            var fieldtoedit = '';
            var rowtoedit = '';
            var rowtoeditvalue = '';
            editor.on('initEdit', function (e, node, data, items) {
              fieldtoedit = jQuery(table.cell(items).node()).attr('class').split(' ')[0];
              rowtoedit = jQuery(table.row(items.row).node()).attr('id');
              rowtoeditvalue = data;
            });
          
            editor.on('initSubmit', function (e, action) {
                if (fieldtoedit == 'custcol_sps_purchaseprice') {
                  if (editor.field('custcol_sps_purchaseprice').val()) {
                  } else {
                    alert('TP Price must be set.');
                    return false;
                  }
                }
            });
            //AMPLIFY CUSTOM CODE END

            var theitemlist = data.items;
            jQuery("#itemsearch").bind('input', function () {
                var itemvalue = jQuery(this).val();
                itemlistcount++
                
                for (var i = 0; i < theitemlist.length; i++) {
                    if (theitemlist[i].searchtitle == itemvalue) {
                        var newrate = theitemlist[i].itemrate;
                        jQuery.get(window.location.href, {'gettype' : 'itemdata', 'itemtype' : theitemlist[i].itemType, columns : JSON.stringify(data.itemColumns), 'itemid' : theitemlist[i].itemid}, null, "json")
                        .then(function (thedata, status, headers, config) {
                            if (thedata) {
                                var newRow = {};
                                for (var i = 0; i < thedata.length; i++) {
                                    var getdata = thedata[i];
                                    for (var key in getdata) {
                                        if (key == 'rate') {
                                            newRow.rate = newrate
                                        } else {
                                            newRow[key] = getdata[key];
                                        }
                                    }
                                }
                                
                                newRow.quantity = 0;
                                newRow.amount = 1 * newRow.rate ? newRow.rate : 0;
                                newRow.DT_RowId = "rows_" + itemlistcount;

                                jQuery('#example').DataTable().row.add(newRow).draw();

                                jQuery("#itemsearch").val('');
                            }
                        });
                    }
                }
            });
    
            jQuery('#example').find('tbody').on( 'click', '#removeitem', function () {
                table.row( jQuery(this).parents('tr') ).remove().draw();
            });
    
            var copyRowCount = 0;
            jQuery('#example').find('tbody').on( 'click', '#copyitem', function () {
                var rowData = table.row(jQuery(this).parents('tr')).data();
    
                copyRowCount++;
                rowData.DT_RowId = "row_copy" + copyRowCount;
                table.row.add(rowData).draw();
            });
                                
        });
    }

Answers

  • colincolin Posts: 12,490Questions: 0Answers: 2,119

    When you say "clear", do you mean it just returns the value to what it was? If so, you want to add {onBlur: 'submit'} - see example here,

    Colin

  • Nwilliams8162Nwilliams8162 Posts: 28Questions: 4Answers: 0

    Colin, thanks for responding. What I mean is I enter a value in the first field and tab off/click off and the value is set (let's say 2). Then on the next field I input my value and hit tab/click off and the previous field (we set to 2) is now cleared out and nothing is there. It's like it sets any other field to blank.

  • allanallan Posts: 54,578Questions: 1Answers: 8,533 Site admin

    Can you give us a link to a page showing that issue please? I haven’t been able to reproduce that error in any of our inline editing examples.

    Thanks,
    Allan

  • Nwilliams8162Nwilliams8162 Posts: 28Questions: 4Answers: 0

    I can but you'll need a login to access the page. I can share that but is there a way to make that private??

  • colincolin Posts: 12,490Questions: 0Answers: 2,119

    If you could message Allan or myself here, by clicking on our name, we'll take a look,

    Colin

  • Nwilliams8162Nwilliams8162 Posts: 28Questions: 4Answers: 0

    Collin,

    I jut sent you a message with the login

Sign In or Register to comment.