Ok i saw many post's on how to serialize the value of dragged items to get hash and they tell how to save them. Now the question is how do i persist the dragged items the next time when user log's in using the has value that i got eg:
<ul class="list">
<li id="id_1">
<div class="item ui-corner-all ui-widget ui-widget-content">
</div>
</li>
<li id="id_2">
<div class="item ui-corner-all ui-widget ui-widget-content">
</div>
</li>
<li id="id_3">
<div class="item ui-corner-all ui-widget ui-widget-content">
</div>
</li>
<li id="id_4">
<div class="item ui-corner-all ui-widget">
</div>
</li>
</ul>
which on serialize will give
"id[]=1&id[]=2&id[]=3&id[]=4"
Now think that i saved it to Sql server database in a single field called SortOrder. Now how do i get the items to these order again ? the code to make these sort is below,without which people didn't know which library i had used to sort and serialize
<script type="t开发者_JAVA百科ext/javascript">
$(document).ready(function() {
$(".list li").css("cursor", "move");
$(".list").sortable();
});
</script>
I believe what Brian is saying is that your table should look like this, if they were sorted in ascending order by the user:
ID Sort Order
1 1
2 2
3 3
4 4
If they were sorted in descending order by the user, the table would look like this:
ID Sort Order
1 4
2 3
3 2
4 1
Then, when you query the database, you would do
SELECT [ID], [Sort Order] FROM [thetable] ORDER BY [Sort Order]
and the list would be sorted by the server.
You can then just output the data in the order the server code provides it in.
Rather than storing a single field, can you store a SortOrder column with the data? You can update the DB with the new sort order, and when you query data from the DB, order it by the sort order. Otherwise, in code, you must do a programmatic sort ordering of data, querying the data into something, then looping through and copying the data to another array/list that's sorted based on this one field.
HTH.
精彩评论