Keep order in HTML list without updating every row in database?

I have an HTML list that can be sorted (using the jQuery sortable API ). I save list items inside the database; each line preserves the order of the elements and the text. How to keep the order of the list items, so I don’t need to update multiple lines when changing the order of the item? List items can be added and removed.

Here is an example of what I am saying:

<ol>
  <li>Go shopping</li> <!-- Order: 1 -->
  <li>Go jogging</li> <!-- Order: 2 -->
  <li>Eat</li> <!-- Order: 3 -->
</ol>

The user moves the Eat list item at the top, now I have to update each row in the database to save the order.

<ol>
  <li>Eat</li> <!-- Order: 3, now update to 1 -->      
  <li>Go shopping</li> <!-- Order: 1, now update to 2 -->
  <li>Go jogging</li> <!-- Order: 2 now update to 3 -->
</ol>
+3
source share
1 answer

, , , - "" , "" ​​, ...
, 1,2,3 3,1,2 .

, , :

  • , . , .
  • , , , , , .

, -, . , , , - "" "".
, , -, , , , .

2

+2

Source: https://habr.com/ru/post/1709262/


All Articles