Sorting Records by ID?

Hi guys,

I’ve created this sortable records,

As you can see it is on ascending order.
Let’s assume I fetch the data records from the database and that is the result.
Now what I want to do is when I move the record number five above number one record.
It’s ID will turn into ID: 1 and record number 1 will now be ID: 2 and so on in ascending order.

How to do this?

Thanks in advance.

Hi there,

If you make your table markup a little more semantic, you can do something like this:

    <meta charset="utf-8">
    <title>Table drag drop example</title>
    <table id="table-1" cellspacing="0" cellpadding="2" border="1">

    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
      function reassignIds(){
        var length = 1;

        $('#table-1 > tbody tr').each(function() {

        onDrop: reassignIds

There is some documentation included with the plugin.

 * Configuration options:
 * onDrop
 *     Pass a function that will be called when the row is dropped. The function takes 2 parameters: the table
 *     and the row that was dropped. You can work out the new order of the rows by using
 *     table.rows.

This means that you can also do something like this:

onDrop: function(table, row){
  console.log(table, row);

which could be the better option depending on the size of the table you are dealing with.


@Pullo ;

Thanks man.