1

I have been working on a sortable list. I want to implement a sortable list like this: http://jqueryui.com/demos/sortable/#connect-lists-through-tabs

It is the ajax communication, that I'm really stuck with.

I have set up a jsfiddle, http://jsfiddle.net/pnrAx/, showing my current code. (Note, it is copy and paste with loads of junk, cleanup needed)

The fields, updating the information on each row are working fine, no problems there. The sorting also works on the screen, I can drag-n-drop items nicely.

To boil the problem down, how can I get the sorted elements from the page, with ajax (json?), into an array on a php page?

From there, it should be pretty easy to update the table.

2 Answers 2

1

what i would do is when you output then html put them into arrays like this

<input type="hidden" name="block[369][id]" value="369"/>
<input type="hidden" name="block[369][menuBolk_id]" value="55"/>
<input type="hidden" name="block[369][matstovuID]" value="39"/>
<input type="text" name="block[369][Heiti]" value="Big Burgara Matskrá" style="width: 60%; font-weight: bold; padding: 4px; line-height: 150%; font-size: 12pt; background-color: #ccc;"/>
<textarea style="width: 60%; background-color: #ccc;" name="Vorulysing"></textarea>
<div style="margin-top: -70px; padding-bottom: 70px;">
    <input type="text" name="block[369][Pris][]" value="Kr 83,-" class="price priceR" style="width: 10%;"/>
    <input type="text" name="block[369][Pris][]" value="" class="price priceC" style="width: 10%;"/>
    <input type="text" name="block[369][Pris][]" value="" class="price priceL" style="width: 10%;"/>
</div>

then when you poste you will have a post of "block" which will be a multi dimensional array

so in this instance what you want is to submit them all at once and process them in the order they are revived so the user would sort then hit a submit button and the form would submit all post data in the the order in which they have sorted them. Does that make sense ?

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I understand. However, it is the sorting of the list I have issues with. I can accept a simple post, to update the fields respectively. I can sort the list, on screen, but I do not know how to get the sort order in my php script
0

On the drop function I would call, via $.ajax, a php page and send the ID, new position, and tab/category ID of that item just dropped in the query string. Then on the new page, get the old sort position from the database and loop through all items that are between the new position and old position of the item dropped either incrementing or decrementing the position of each item.

1 Comment

How do I send the position from jQuery?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.