Skip to content
Advertisement

How to order bootstrap panels in a grid when a new value is added?

I have a grid based on bootstrap 3 with col / rows inside each col there is a panel with a value, the values are got from DB yet ordered but the user could add a new panel manually and i would be able to set it ordered correctly..

like my grid could contain

1 2 3 +

when + is clicked the user could add 4 that should be added after 3 or he could add 1.50 which should be added before 2 and so on

Here is how my grid looks like with an example of static add

JavaScript
JavaScript

So how could i reorder the panels each time a new item is added?

Advertisement

Answer

As, you are displaying prices inside your div you can use .find and .replace to get exact price from divs and compare them inside sort function then append sorted divs inside your main div again.

Demo Code :

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement