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.
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;
}
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?
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.
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.
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);
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.
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?
Comments
http://www.getfuelcms.com/blog/2011/03/14/fuel-cms-0.9.3-released
Where do I put that field?
Ive set it as INT.
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; }
How can I add this field to the list?
Any toughts?
Do I have to call in a special JS controller or something? What am I missing?
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.
$where = array($this->model->key_field() => $row);
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.
$this->model->debug_query()
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?
https://github.com/daylightstudio/FUEL-CMS/commit/cb4c9d1c03d4af94dcd92e2016d1323916bbd9bc