AutoFill Increment shows NaN

AutoFill Increment shows NaN

rabbitrabbitrabbitrabbit Posts: 1Questions: 1Answers: 0
edited September 2023 in Free community support

Link to test case: https://datatables.net/extensions/autofill/examples/initialisation/plugins.html
Debugger code (debug.datatables.net): None that I can see in the console.
Error messages shown: None that I can see.

Description of problem:
When using the AutoFill Increment feature to increment numbers by any amount, the cells are filled by 'NaN'.

On the datatables website linked above, after selecting the first Age value (33), then dragging down the cell down, I get the prompt to Increment/decrement by x, Fill all or Cancel. If I click the up arrow to change the amount to increment by, the dialog dissapears and the cells are filled with 'NaN'. Even if I click in the box to change the amount to increment/decrement by, it causes the same behavior.

I cannot get this working and assume it's something to with it handling numbers as strings and failing?

I've tried in Firefox, Chrom and Edge. All have the same behaviour.

Answers

  • rabbitrab73rabbitrab73 Posts: 5Questions: 0Answers: 0
  • rabbitrab73rabbitrab73 Posts: 5Questions: 0Answers: 0

    This is the only example I've found to be working but I'm not sure what the difference is between it and my code.
    https://jsfiddle.net/rk2n8up4/2/

  • kthorngrenkthorngren Posts: 21,337Questions: 26Answers: 4,954

    The fiddle you found uses Autofill 2.3.4 where the example uses 2.6.0. I updated the fiddle to use 2.6.0 and the NaN error is recreated.
    https://jsfiddle.net/rm9nzube/1/

    I would say you are correct that the numbers are being handled as strings and the error was introduced after 2.3.4. @allan will need to take a look.

    Kevin

  • rabbitrab73rabbitrab73 Posts: 5Questions: 0Answers: 0

    Thanks Kevin,
    I'll wait to hear from @allan.
    Tom

  • rabbitrab73rabbitrab73 Posts: 5Questions: 0Answers: 0
    edited September 2023

    I ended deleting the existing 'increment' functionality and writing my own (very similar, copied and pasted) version of an increment and decrement which has things working again.

    My suspicion is there is something wrong with the <input> field in the popup with the updown field. I've resorted to a 'Increment' and a 'Decrement' option without the ability to change the number to count by. I only need to go up or down by 1 so it's not a problem for me.

    The actual code of the 'execute' sections is copied straight from the source.

    delete $.fn.dataTable.AutoFill.actions.increment;
    
    DataTable.AutoFill.actions.increment = {
        available: function (dt, cells) {
            return cells[0].length === 1 && cells[0][0].index.column === 1;
        },
    
        option: function (dt, cells) {
            return 'Increment tag numbers';
        },
    
            execute: function ( dt, cells, node ) {
                var value = cells[0][0].data * 1;
                var increment = 1;
    
                for ( var i=0, ien=cells.length ; i<ien ; i++ ) {
                    for ( var j=0, jen=cells[i].length ; j<jen ; j++ ) {
                        cells[i][j].set = value;
    
                        value += increment;
                    }
                }
            }
      };
    
      DataTable.AutoFill.actions.decrement = {
        available: function (dt, cells) {
            return cells[0].length === 1 && cells[0][0].index.column === 1;
        },
    
        option: function (dt, cells) {
            return 'Decrement tag numbers';
        },
    
            execute: function ( dt, cells, node ) {
                var value = cells[0][0].data * 1;
                var increment = -1;
    
                for ( var i=0, ien=cells.length ; i<ien ; i++ ) {
                    for ( var j=0, jen=cells[i].length ; j<jen ; j++ ) {
                        cells[i][j].set = value;
    
                        value += increment;
                    }
                }
            }
      };
    
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Apologies - you are absolutely right. There is a bug in the current release of AutoFill for the increment button. I've committed a fix and it will be in the nightly shortly and the next release of AutoFill.

    Allan

  • rabbitrab73rabbitrab73 Posts: 5Questions: 0Answers: 0

    Thank you so much!
    This is by far the best editor datatable tool I've used! Thanks again!

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    :) Thank you!

Sign In or Register to comment.