Reordering records

How do I make the Reorder button appear on top of the list?
I've tried setting fields like 'order' 'position' on the database table but none of them work.

Thanks!

Comments

  • edited June 2011
    'precedence' is the default field name. This blog posts talks about it a little more (in particular the "precedence_col" module parameter:
    http://www.getfuelcms.com/blog/2011/03/14/fuel-cms-0.9.3-released
  • edited 5:55PM
    Thanks.
  • edited 5:55PM
    Can't get it to work :(
    Where do I put that field?
  • edited 5:55PM
    You should put it in the table your module is using.
  • edited 5:55PM
    Doesnt seem to work. Any toughts?
    Ive set it as INT.
  • edited 5:55PM
    Try adding "precedence" to the fields returned by the list_items method. This can be done one of two ways:
    1. By add the following to your MY_fuel_modules config file to the appropriate module (where the array is the columns you want to display, but you must include the id column which is hidden)
    'table_headers' => array( 'id', 'name', 'client', 'precedence', 'published', ),
    2. By overwriting the list_items method in the model like so:
    function list_items($limit = null, $offset = null, $col = 'precedence', $order = 'desc') { $this->db->select('id, name, client, precedence, published', FALSE); $data = parent::list_items($limit, $offset, $col, $order); return $data; }
  • edited 5:55PM
    I figured out that I must add a field with id "precedence".
    How can I add this field to the list?
  • edited 5:55PM
    One of the two methods mentioned above should do the trick.
  • edited 5:55PM
    Still can't get it to work, ive done both methods but the button wont show up.
    Any toughts?
  • edited 5:55PM
    @jplozano are you sure u've added the 'precedence' field in the list_items select query? That did the trick for me...
  • edited 5:55PM
    oh and make sure u don't have NULL values for 'precedence' in the DB
  • edited 5:55PM
    Excellent, got it! Thank you both of you!
  • edited December 2012
    I've included a 'precedence' field in my table (set to INT) and it shows up fine when I list the items. However, when when I click "Rearrange" and drag the elements around, they change position but the 'precedence' column is not updated.

    Do I have to call in a special JS controller or something? What am I missing?
  • edited 5:55PM
    You shouldn't have to do anything else. What version of FUEL are you running and what browser? If you look at the browser console, there should be a javascript ajax call after you drag a row to update the table.
  • edited 5:55PM
    Ok, I've found the problem: my key field was not named 'id'.

    The console was showing a Database Error because "Unknown column 'id' in 'where clause'" (DB_driver.php line 330). If I rename my key field to 'id', rearranging works.

    However, I usually use different types of key field names (i.e. 'types_id') and set the key_field property accordingly in my model. This causes the "rearrange" to fail.

    Do you see a workaround allowing me to keep custom key fields and still be able to rearrange items? I guess it would probably require a fix but it would be great for users who don't use the generic 'id' field as a primary key in their tables.
  • edited 5:55PM
    I think it's a bug we should probably fix. Does it work for you if you change in the fuel/modules/fuel/controllers/module.php file the items_precedence method, the "id" value in the where array to the following:
    $where = array($this->model->key_field() => $row);
  • edited 5:55PM
    A step in the right direction! The custom key is accepted.

    Instead of doing nothing and throwing an error, it now reloads the list. However, it is only reloading and ordering using the old precedence values.

    In other words, if I drag ITEM1 (precedence 1) down below ITEM3 (precedence 3), it displays the progress indicator for a second and then reorders the list and shows ITEM1 in first place, still with a precedence of 1.
  • edited 5:55PM
    Are you able to debug it and see if there are any sequel errors after the update in the module::items_precedence method:
    $this->model->debug_query()
  • edited 5:55PM
    OK, it's running this query on my 'types' table:

    UPDATE `types` SET `precedence` = 2 WHERE `types_id` = '2' UPDATE `types` SET `precedence` = 3 WHERE `types_id` = '1'

    My 'types' table has only three fields: 'types_id' (INT), 'types_name' (VARCHAR), 'precendence' (INT). Currently, there are only three rows of data:
    row1 -> 3,Images,0
    row2 -> 4,Video,0
    row3 -> 5,HTML,0

    Why is it trying to set 'precedence' on 'types_id's 1 and 2? The only rows currently in the table have ids 3,4 and 5?
  • edited 5:55PM
    I'm running version 1.0 of Fuel, by the way.
  • edited 5:55PM
    OK... I think I may have found the issue. The Data_table class uses the records 'id' by default. I needed to explicitly set it to the model's key_field value in the module controller:
    https://github.com/daylightstudio/FUEL-CMS/commit/cb4c9d1c03d4af94dcd92e2016d1323916bbd9bc
  • edited 5:55PM
    Fantastic, works like a charm! Thanks for the help!
  • edited 5:55PM
    No problem.
Sign In or Register to comment.