I'm trying to insert new row with the DOM method in JavaScript. Each row in my table is order by Begin date. My new record also contain Begin date. Once I get response from the server I should insert the row in the table. I'm wondering what is the best way to compare the new Begin date with the dates that are already in the table? Also that logic should somehow return some kind of id where that row should be inserted. I can't think of any way to get this to work.
Here is example of my table:
Begin Date End Date City
05/02/2017 New York
03/27/2017 05/1/2017 Dallas
03/25/2017 03/26/2017 Seattle
As you can see above my table will place the most recent begin date on the top. If user pick to insert new record with begin date of 03/26/2017 I have to place that record between Dallas and Seattle records in my table. If anyone have idea how and what is the best way to approach this please let me know. I use Vanilla JavaScript.