I created a library which adds a drop-down menu of categories into the grid header.
[color=#66cc00]___________________________________________[/color]
Download here:
[attachment=356:grocery_crud_categories.php]
updated 14/11/2012
[color=#66cc00]___________________________________________[/color]
You can do the sorting by category by means of the menu (without Ajax yet)
This library supports single-level lists and adjacency list tree.
[b]And most importantly, this library do not require changes to the view![/b]
[attachment=342:a.jpg][attachment=343:b.jpg]
[b]How to use:[/b]
function goods()
{
$this->load->library('grocery_CRUD');
$this->load->library('grocery_crud_categories') ;
$crud = new grocery_CRUD();
$crud->set_relation('goods_category','adj_category','category_name');
$crud->set_table('adj_goods');
$config = array(
'table_name'=>'adj_goods',
'related_table'=>'adj_category',
'sort_field'=>'goods_category',
'categories_primary_key'=>'category_id',
'related_title_field'=>'category_name',
'parent_field'=>'parent_id',
'order_by'=>'category_name',
'first_url' => base_url().__CLASS__.'/'.__FUNCTION__,
'segment_name' => 'category';
'style' => 'height:24px; width: 200px;',
'class'=>'your_class',
'text'=>array('all_rows'=>'select category');
);
$categories = new grocery_crud_categories($crud,$config);
//Attention! Don't use the $crud->render();
//Use the $categories->render();
// But there is second method. You can read about that below.
$output = $categories->render();
$this->_example_output($output);
}
[b]The second method of integrate.[/b]
$categories = new grocery_crud_categories($crud,$config);
$dropdown = $categories->get_dropdown();
$output = $crud->render();
$output->output = $dropdown . $output->output;
$this->_example_output($output);
[b]Config:[/b]
[indent=1][color=#ff0000]1)[/color][color=#ff0000]*[/color][color=#ff0000] [/color]'[color=#8b4513]table_name[/color]'=>'adj_goods',
[color=#ff0000]2)[/color][color=#ff0000]*[/color] '[color=#8b4513]related_table[/color]'=>'adj_category',
[color=#ff0000]3)[/color][color=#ff0000]*[/color] '[color=#8b4513]sort_field[/color]'=>'goods_category',
[color=#ff0000]4)[/color][color=#ff0000]*[/color] '[color=#8b4513]categories_primary_key[/color]'=>'category_id',
[color=#ff0000]5)[/color][color=#ff0000]*[/color] '[color=#8b4513]related_title_field[/color]'=>'category_name',
[color=#ff0000]6)[/color] '[color=#8b4513]parent_field[/color]'=>'parent_id', - [color=#ff0000]if you use a single-level list set this param as [/color][color=#0000ff]"false",[/color][/indent]
[indent=1]click -> [attachment=346:how.jpg][/indent]
[indent=1][color=#ff0000]7)[/color] '[color=#8b4513]order_by[/color]'=>'category_name' - lets you set an ORDER BY clause. Example: 'order_by'=>"position DESC,name ASC"[/indent]
[indent=1][color=#ff0000]8)[/color][color=#ff0000]* [/color]'[color=#8b4513]first_url'[/color] => base_url().__CLASS__.'/'.__FUNCTION__ - base url for the links[/indent]
[indent=1][color=#ff0000]9)[/color]'[color=#8b4513]segment_name[/color]' = 'category'; - segment name. http://localhost/examples/goods/[color=#ff0000]category[/color]/[color=#0000ff]7[/color][/indent]
[indent=1]
[color=#ff0000]10)[/color] '[color=#8b4513]style[/color]' => 'height:24px; width: 200px;' - you can use your styles for this menu
[color=#ff0000]11) [/color]'[color=#8b4513]class[/color]'=>'your_class' - you can use a class too[/indent]
[indent=1][color=#ff0000]12) [/color]'[color=#8b4513]text[/color][color=#daa520]'[/color]=>array('all_rows'=>'all categories') - text for the first element of list ( "<option>all categories</option>")[/indent]
[indent=1][color=#ff0000]*[/color] - element is required.[/indent]
[indent=1]-----------------------------------[/indent]
[indent=1]I created this library for the flexigrid theme, but it works with the datatable (you can modify the code as you like ).[/indent]
[indent=1]P.S: If you have suggestions for improving the library, I will be glad to hear. [/indent]
[indent=1]P.S.S. Code can contain some bugs . If you find a bug - report, please.[/indent]
[indent=1]Sorry, my English is bad .[/indent]