• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change order of records - How's it look??

I wanted to give my client the ability to reorder a list of records and I thought the simplest way was to move a record up one spot at a time and have the record above move down one. Each row has a field called "p_order". When a new record is inserted, a query is made to determine the highest order number, adds one and inserts it.

When you click the "up" link as show in the view below:
- The current value of "p_order" is given to the record above.
- The current value of "p_order" has 1 added to it and updated for the current record.

How's it look? I figured when refined this could be very useful for a lot of people.

The View - for now, just a link that says "up"
<?php echo anchor("manage/moveUp/$row->p_order/$row->p_cat/$row->p_id",'up'); ?>

The Controller
function moveUp($order,$cat,$id)


The Model
function moveUp($order,$cat,$id)

In addition, here is the controller to add a new record, notice the first query figures out the order:
/* Insert Record Action*/

function insertRecord()


The only issue with this method is if the list of records is very long, it's a real pain in the butt. Especially if you're moving a record from the bottom to the top. Also, what if your records are paginated?

You could alternatively use something like jQueryUI, which has a 'sortables' function which will turn a set of elements into a sortable list, drag and drop style. The only downside is that saving the changes would either require you to update all rows or save a second copy for comparison to know which rows were changed.

Agreed but this is for around twenty records so I think it's pretty manageable.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.