Max value from column - more clean solution

Max value from column - more clean solution

VitalizVitaliz Posts: 71Questions: 7Answers: 1
edited October 2015 in General

Hi, Allan.
I'm find a function to return the max value in a table column and set new max value. I find this: https://datatables.net/forums/discussion/20956/how-to-find-the-max-value-in-a-column
I have tested your solution http://jsfiddle.net/WTXM7/44/ , but I found it work one time only, and than use stable value - so it don`t count new added rows.
I tried fix it, but failed(.
May you fix this bug? Or it is a problem with http://jsfiddle.net?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin

    The function to fix the max value seems to work just fine. it finds the maximum number and then you assigning it to col3. I think you might want to assign the max found number +1! :-)

    Allan

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    Sorry, Allan.
    I started playing with the code from FuzzyBunnyFeet version http://jsfiddle.net/FuzzyBunnyFeet/WTXM7/53/.
    He assigned the max found number +1, but code not working properly(.
    After that I test your code and ask you question.
    Eyes in the soap, as Russians says))))
    But after I add 1 to max number,it worked just as well as the FuzzyBunnyFeet variant, count only up to 10.
    Here is my fork of your code with "+1" added. http://jsfiddle.net/du3h1Lyy/1/

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin
    Answer ✓

    Okay - it only goes up to ten because the sort() method call is sorting the data by string. You just need to add a little function to make it sort by number: http://jsfiddle.net/du3h1Lyy/2/ .

    Allan

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1
    edited October 2015

    It's exellent now. It's working good and it's good example of jQuery chaining. Compact and clean code. Thank you very much.

This discussion has been closed.