Rob D. A.
Rob D. A.

Reputation: 134

How to check current order of rows in sortable table?

Working on a project "sortable" (rows vertically :)) list of items, but I met the problem and I don't know how to solve it.

each row got own id. How can I check new order then save it into database so next time I will load data it will be displayed in "saved" order ?

Upvotes: 0

Views: 200

Answers (2)

johannes
johannes

Reputation: 1448

Give the items a classname. When the items are sorted they will have the right order in the classnames-array. For example:

<div id="list">
   <div class="item">item 1</div>
   <div class="item">item 2</div>
   <div class="item">item 3</div>
</div>

$('.item').each(function(){
    //save item[n] to your database using $.ajax
});

Upvotes: 1

federico lucca
federico lucca

Reputation: 13

try to save a new field somewhere (could be table "configuration") where save the model table name and the type of sorting and on the init method of the jquery table uses the field to sort quickly on frontend at load time

Upvotes: 0

Related Questions