1

Summary: I have a table where rows are added for each btn click. I am using jquery-ui sortable() function to move/sort the rows.

Let say i have this:

<tbody>
  <tr><td>A</td></tr>
  <tr><td>B</td></tr>
  <tr><td>C</td></tr>
  <tr><td>D</td></tr>
  <tr><td>E</td></tr>
  <tr><td>F</td></tr>
</tbody>

Issue: I can move the rows using sortable() function. But i am not able to update the elements in the rows. i am using this

$('.report-configuration .configuration-table tbody').sortable({
'change': function(event, ui){
    arr=['a','b','c','d','e','f'];
    console.log(ui);
    var tmp = arr.splice(ui.originalPostion);//i am missing logic here
    arr.splice(ui.postion, tmp);
    console.log(arr);

}});

I am looking for the logic to update the positions in the array.

0

1 Answer 1

5

After sortable has ended the html is also changed. With jQuery you can select the changed html and determine the correct sequence.

In your change callback function do something like this, note arr has the new array with correct sequence:

var arr = []
$(this).find('td').each(function() {
  arr.push($(this).html());
});
console.log(arr);
Sign up to request clarification or add additional context in comments.

1 Comment

just extending your solution: var arr = $(this).find('td').map(function(e){ return e.innerHTML }) should do the job

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.